- Deleted unused classes
- Refined and added javadoc - Disabled MetaDataWriter
This commit is contained in:
@@ -1,116 +1,141 @@
|
||||
package com.greinet.tvtotalripper.ui;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.GridBagLayout;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JList;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.event.ListSelectionEvent;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author agreiner
|
||||
*/
|
||||
public class BaseRipperPanel {
|
||||
|
||||
private final JPanel panel;
|
||||
private JList<String> listPanel;
|
||||
private JTextField textField;
|
||||
private final JButton button;
|
||||
private final JLabel label;
|
||||
private Map<String, String> elements;
|
||||
|
||||
public BaseRipperPanel(Map<String, String> elements){
|
||||
this.elements = elements;
|
||||
|
||||
if(elements.isEmpty()){
|
||||
elements.put("Dummy-Key", "Dummy-URL");
|
||||
}
|
||||
|
||||
panel = new JPanel(false);
|
||||
panel.setLayout(new GridBagLayout());
|
||||
|
||||
GridBagConstraints c = new GridBagConstraints();
|
||||
c.gridx = 0;
|
||||
c.gridy = 0;
|
||||
c.gridwidth = 3;
|
||||
c.fill = GridBagConstraints.BOTH;
|
||||
c.weightx = 0.75;
|
||||
|
||||
textField = new JTextField();
|
||||
textField.setEditable(false);
|
||||
panel.add(textField,c);
|
||||
|
||||
button = new JButton("Select");
|
||||
c.gridx = 3;
|
||||
c.gridwidth = 2;
|
||||
c.weightx = 0.25;
|
||||
|
||||
panel.add(button,c);
|
||||
|
||||
|
||||
List<String> names = new ArrayList<>(elements.keySet());
|
||||
Collections.sort(names);
|
||||
|
||||
listPanel = new JList<>(names.toArray(new String[elements.keySet().size()]));
|
||||
JScrollPane scrollPane = new JScrollPane();
|
||||
scrollPane.setViewportView(listPanel);
|
||||
listPanel.setLayoutOrientation(JList.VERTICAL);
|
||||
listPanel.setSelectedIndex(0);
|
||||
|
||||
listPanel.addListSelectionListener((ListSelectionEvent e) -> {
|
||||
textField.setText(listPanel.getSelectedValue());
|
||||
});
|
||||
textField.setText(listPanel.getSelectedValue());
|
||||
|
||||
c.gridx = 0;
|
||||
c.gridy = 1;
|
||||
c.gridwidth = 5;
|
||||
c.gridheight = 5;
|
||||
c.weightx = 0;
|
||||
|
||||
panel.add(scrollPane,c);
|
||||
|
||||
label = new JLabel(Integer.toString(elements.keySet().size()));
|
||||
label.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
|
||||
|
||||
|
||||
c.gridx = 4;
|
||||
c.gridy = 6;
|
||||
c.gridwidth = 1;
|
||||
c.gridheight = 1;
|
||||
c.fill = GridBagConstraints.NONE;
|
||||
c.anchor = GridBagConstraints.EAST;
|
||||
|
||||
panel.add(label, c);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
public JPanel getJPanel(){
|
||||
return panel;
|
||||
}
|
||||
|
||||
public JButton getJButton(){
|
||||
return button;
|
||||
}
|
||||
|
||||
public String getCurrentSelected(){
|
||||
return elements.get(listPanel.getSelectedValue());
|
||||
}
|
||||
|
||||
public JList getJList(){
|
||||
return listPanel;
|
||||
}
|
||||
|
||||
}
|
||||
package com.greinet.tvtotalripper.ui;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.GridBagLayout;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JList;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.event.ListSelectionEvent;
|
||||
|
||||
/**
|
||||
* The base panel for show and episode visualization
|
||||
*/
|
||||
public class BaseRipperPanel {
|
||||
|
||||
/** The JPanel */
|
||||
private final JPanel panel;
|
||||
/** The Jlist for the elements */
|
||||
private JList<String> listPanel;
|
||||
/** The text field for the currently selected element */
|
||||
private JTextField textField;
|
||||
/** The button to select the currently selected element */
|
||||
private final JButton button;
|
||||
/** The label for the element count */
|
||||
private final JLabel label;
|
||||
/** The map for the elements */
|
||||
private final Map<String, String> elements;
|
||||
|
||||
/**
|
||||
* Create a base panel the display elements and select a specific one
|
||||
* @param elements the elements
|
||||
*/
|
||||
public BaseRipperPanel(Map<String, String> elements){
|
||||
this.elements = elements;
|
||||
|
||||
if(elements.isEmpty()){
|
||||
elements.put("Dummy-Key", "Dummy-URL");
|
||||
}
|
||||
|
||||
panel = new JPanel(false);
|
||||
panel.setLayout(new GridBagLayout());
|
||||
|
||||
GridBagConstraints c = new GridBagConstraints();
|
||||
c.gridx = 0;
|
||||
c.gridy = 0;
|
||||
c.gridwidth = 3;
|
||||
c.fill = GridBagConstraints.BOTH;
|
||||
c.weightx = 0.75;
|
||||
|
||||
textField = new JTextField();
|
||||
textField.setEditable(false);
|
||||
panel.add(textField,c);
|
||||
|
||||
button = new JButton("Select");
|
||||
c.gridx = 3;
|
||||
c.gridwidth = 2;
|
||||
c.weightx = 0.25;
|
||||
|
||||
panel.add(button,c);
|
||||
|
||||
|
||||
List<String> names = new ArrayList<>(elements.keySet());
|
||||
Collections.sort(names);
|
||||
|
||||
listPanel = new JList<>(names.toArray(new String[elements.keySet().size()]));
|
||||
JScrollPane scrollPane = new JScrollPane();
|
||||
scrollPane.setViewportView(listPanel);
|
||||
listPanel.setLayoutOrientation(JList.VERTICAL);
|
||||
listPanel.setSelectedIndex(0);
|
||||
|
||||
listPanel.addListSelectionListener((ListSelectionEvent e) -> {
|
||||
textField.setText(listPanel.getSelectedValue());
|
||||
});
|
||||
textField.setText(listPanel.getSelectedValue());
|
||||
|
||||
c.gridx = 0;
|
||||
c.gridy = 1;
|
||||
c.gridwidth = 5;
|
||||
c.gridheight = 5;
|
||||
c.weightx = 0;
|
||||
|
||||
panel.add(scrollPane,c);
|
||||
|
||||
label = new JLabel(Integer.toString(elements.keySet().size()));
|
||||
label.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
|
||||
|
||||
|
||||
c.gridx = 4;
|
||||
c.gridy = 6;
|
||||
c.gridwidth = 1;
|
||||
c.gridheight = 1;
|
||||
c.fill = GridBagConstraints.NONE;
|
||||
c.anchor = GridBagConstraints.EAST;
|
||||
|
||||
panel.add(label, c);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the JPanel
|
||||
* @return the JPanel
|
||||
*/
|
||||
public JPanel getJPanel(){
|
||||
return panel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the selection JButton
|
||||
* @return the JButton
|
||||
*/
|
||||
public JButton getJButton(){
|
||||
return button;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the String representing the currently selected element
|
||||
* @return the selected element
|
||||
*/
|
||||
public String getCurrentSelected(){
|
||||
return elements.get(listPanel.getSelectedValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Jlist of the elements
|
||||
* @return the JList
|
||||
*/
|
||||
public JList getJList(){
|
||||
return listPanel;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,143 +1,164 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package com.greinet.tvtotalripper.ui;
|
||||
|
||||
import com.greinet.tvtotalripper.download.DownloadTask;
|
||||
import java.awt.Color;
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.GridBagLayout;
|
||||
import java.beans.PropertyChangeEvent;
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.DefaultListModel;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JList;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.ListSelectionModel;
|
||||
import javax.swing.event.ListSelectionEvent;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author agreiner
|
||||
*/
|
||||
public class DownloadRipperPanel implements PropertyChangeListener{
|
||||
|
||||
private final JPanel panel;
|
||||
private JList<DownloadTask> listTasks;
|
||||
private DefaultListModel<DownloadTask> listModel;
|
||||
private JTextField textSelectedTask;
|
||||
private final JLabel labelTaskCount;
|
||||
|
||||
private final List<DownloadTask> downloadTasks;
|
||||
|
||||
private DownloadTaskInformationPanel infoPanel;
|
||||
|
||||
public DownloadRipperPanel(){
|
||||
|
||||
downloadTasks = new ArrayList<>();
|
||||
|
||||
panel = new JPanel();
|
||||
panel.setLayout(new GridBagLayout());
|
||||
|
||||
GridBagConstraints c = new GridBagConstraints();
|
||||
|
||||
c.gridx = 0;
|
||||
c.gridy = 0;
|
||||
c.gridwidth = 5;
|
||||
c.fill = GridBagConstraints.BOTH;
|
||||
c.weightx = 0.5;
|
||||
textSelectedTask = new JTextField();
|
||||
textSelectedTask.setEditable(false);
|
||||
panel.add(textSelectedTask, c);
|
||||
|
||||
|
||||
listModel = new DefaultListModel<>();
|
||||
listTasks = new JList<>(listModel);
|
||||
listTasks.setSelectedIndex(ListSelectionModel.SINGLE_SELECTION);
|
||||
JScrollPane scrollPane = new JScrollPane();
|
||||
scrollPane.setViewportView(listTasks);
|
||||
listTasks.setLayoutOrientation(JList.VERTICAL);
|
||||
|
||||
c.gridx = 0;
|
||||
c.gridy = 1;
|
||||
c.gridwidth = 5;
|
||||
c.gridheight = 5;
|
||||
c.weightx = 0.5;
|
||||
panel.add(scrollPane, c);
|
||||
|
||||
infoPanel = new DownloadTaskInformationPanel();
|
||||
c.gridx = 5;
|
||||
c.gridy = 0;
|
||||
c.gridwidth = 5;
|
||||
c.weightx = 0.5;
|
||||
c.fill = GridBagConstraints.BOTH;
|
||||
panel.add(infoPanel, c);
|
||||
|
||||
listTasks.addListSelectionListener((ListSelectionEvent e) -> {
|
||||
if(listTasks.getSelectedValue()!=null){
|
||||
textSelectedTask.setText(listTasks.getSelectedValue().toString());
|
||||
infoPanel.setInformation(listTasks.getSelectedValue());
|
||||
infoPanel.selectedDownloadTask = listTasks.getSelectedValue();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
labelTaskCount = new JLabel(Integer.toString(listTasks.getModel().getSize()));
|
||||
labelTaskCount.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
|
||||
|
||||
c.gridx = 4;
|
||||
c.gridy = 6;
|
||||
c.gridwidth = 1;
|
||||
c.gridheight = 1;
|
||||
c.fill = GridBagConstraints.NONE;
|
||||
c.anchor = GridBagConstraints.EAST;
|
||||
panel.add(labelTaskCount, c);
|
||||
}
|
||||
|
||||
public JPanel getJPanel(){
|
||||
return panel;
|
||||
}
|
||||
|
||||
public DownloadTask getSelectedTask(){
|
||||
return listTasks.getSelectedValue();
|
||||
}
|
||||
|
||||
public void addTask(DownloadTask task){
|
||||
downloadTasks.add(task);
|
||||
task.execute();
|
||||
listModel.addElement(task);
|
||||
updateTaskCount();
|
||||
task.addPropertyChangeListener(this);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void propertyChange(PropertyChangeEvent evt) {
|
||||
if(evt.getNewValue().equals(101)){
|
||||
Optional<DownloadTask> taskToRemove = downloadTasks.stream().filter(t -> Long.toString(t.getEpisodeWrapper().getId()).equals(evt.getPropertyName())).findFirst();
|
||||
if(taskToRemove.isPresent()){
|
||||
if(listTasks.getSelectedValue() != null && taskToRemove.get().equals(listTasks.getSelectedValue())){
|
||||
infoPanel.clearInformation();
|
||||
textSelectedTask.setText("");
|
||||
}
|
||||
downloadTasks.remove(taskToRemove.get());
|
||||
listModel.removeElement(taskToRemove.get());
|
||||
updateTaskCount();
|
||||
|
||||
}
|
||||
}
|
||||
panel.repaint();
|
||||
}
|
||||
|
||||
private void updateTaskCount(){
|
||||
labelTaskCount.setText(Integer.toString(listTasks.getModel().getSize()));
|
||||
}
|
||||
}
|
||||
package com.greinet.tvtotalripper.ui;
|
||||
|
||||
import com.greinet.tvtotalripper.download.DownloadTask;
|
||||
import java.awt.Color;
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.GridBagLayout;
|
||||
import java.beans.PropertyChangeEvent;
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.DefaultListModel;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JList;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.ListSelectionModel;
|
||||
import javax.swing.event.ListSelectionEvent;
|
||||
|
||||
/**
|
||||
* A download panel to show the current downloads
|
||||
*/
|
||||
public class DownloadRipperPanel implements PropertyChangeListener{
|
||||
|
||||
/** The JPanel for download task visualization */
|
||||
private final JPanel panel;
|
||||
/** The JList for the downloads */
|
||||
private JList<DownloadTask> listTasks;
|
||||
/** The ListModel for the DownloadTasks */
|
||||
private final DefaultListModel<DownloadTask> listModel;
|
||||
/** The text field for the currently selected task */
|
||||
private JTextField textSelectedTask;
|
||||
/** The JLabel for the DownloadTask count */
|
||||
private final JLabel labelTaskCount;
|
||||
/** The list of download tasks */
|
||||
private final List<DownloadTask> downloadTasks;
|
||||
/** The information panel for the currently selected task */
|
||||
private DownloadTaskInformationPanel infoPanel;
|
||||
|
||||
/**
|
||||
* Create a download panel
|
||||
*/
|
||||
public DownloadRipperPanel(){
|
||||
|
||||
downloadTasks = new ArrayList<>();
|
||||
|
||||
panel = new JPanel();
|
||||
panel.setLayout(new GridBagLayout());
|
||||
|
||||
GridBagConstraints c = new GridBagConstraints();
|
||||
|
||||
c.gridx = 0;
|
||||
c.gridy = 0;
|
||||
c.gridwidth = 5;
|
||||
c.fill = GridBagConstraints.BOTH;
|
||||
c.weightx = 0.5;
|
||||
textSelectedTask = new JTextField();
|
||||
textSelectedTask.setEditable(false);
|
||||
panel.add(textSelectedTask, c);
|
||||
|
||||
|
||||
listModel = new DefaultListModel<>();
|
||||
listTasks = new JList<>(listModel);
|
||||
listTasks.setSelectedIndex(ListSelectionModel.SINGLE_SELECTION);
|
||||
JScrollPane scrollPane = new JScrollPane();
|
||||
scrollPane.setViewportView(listTasks);
|
||||
listTasks.setLayoutOrientation(JList.VERTICAL);
|
||||
|
||||
c.gridx = 0;
|
||||
c.gridy = 1;
|
||||
c.gridwidth = 5;
|
||||
c.gridheight = 5;
|
||||
c.weightx = 0.5;
|
||||
panel.add(scrollPane, c);
|
||||
|
||||
infoPanel = new DownloadTaskInformationPanel();
|
||||
c.gridx = 5;
|
||||
c.gridy = 0;
|
||||
c.gridwidth = 5;
|
||||
c.weightx = 0.5;
|
||||
c.fill = GridBagConstraints.BOTH;
|
||||
panel.add(infoPanel, c);
|
||||
|
||||
listTasks.addListSelectionListener((ListSelectionEvent e) -> {
|
||||
if(listTasks.getSelectedValue()!=null){
|
||||
textSelectedTask.setText(listTasks.getSelectedValue().toString());
|
||||
infoPanel.setInformation(listTasks.getSelectedValue());
|
||||
infoPanel.selectedDownloadTask = listTasks.getSelectedValue();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
labelTaskCount = new JLabel(Integer.toString(listTasks.getModel().getSize()));
|
||||
labelTaskCount.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
|
||||
|
||||
c.gridx = 4;
|
||||
c.gridy = 6;
|
||||
c.gridwidth = 1;
|
||||
c.gridheight = 1;
|
||||
c.fill = GridBagConstraints.NONE;
|
||||
c.anchor = GridBagConstraints.EAST;
|
||||
panel.add(labelTaskCount, c);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the JPanel
|
||||
* @return the JPanel
|
||||
*/
|
||||
public JPanel getJPanel(){
|
||||
return panel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the currently selected task
|
||||
* @return the selected task
|
||||
*/
|
||||
public DownloadTask getSelectedTask(){
|
||||
return listTasks.getSelectedValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a download task to be executed
|
||||
* @param task
|
||||
*/
|
||||
public void addTask(DownloadTask task){
|
||||
downloadTasks.add(task);
|
||||
task.execute();
|
||||
listModel.addElement(task);
|
||||
updateTaskCount();
|
||||
task.addPropertyChangeListener(this);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Listen to the property change events and remove a task if the new value is 101
|
||||
* @param evt the event parameters
|
||||
*/
|
||||
@Override
|
||||
public void propertyChange(PropertyChangeEvent evt) {
|
||||
if(evt.getNewValue().equals(101)){
|
||||
Optional<DownloadTask> taskToRemove = downloadTasks.stream().filter(t -> Long.toString(t.getEpisodeWrapper().getId()).equals(evt.getPropertyName())).findFirst();
|
||||
if(taskToRemove.isPresent()){
|
||||
if(listTasks.getSelectedValue() != null && taskToRemove.get().equals(listTasks.getSelectedValue())){
|
||||
infoPanel.clearInformation();
|
||||
textSelectedTask.setText("");
|
||||
}
|
||||
downloadTasks.remove(taskToRemove.get());
|
||||
listModel.removeElement(taskToRemove.get());
|
||||
updateTaskCount();
|
||||
|
||||
}
|
||||
}
|
||||
panel.repaint();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the current task count
|
||||
*/
|
||||
private void updateTaskCount(){
|
||||
labelTaskCount.setText(Integer.toString(listTasks.getModel().getSize()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,126 +1,147 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package com.greinet.tvtotalripper.ui;
|
||||
|
||||
import com.greinet.tvtotalripper.download.DownloadTask;
|
||||
import java.awt.GridLayout;
|
||||
import java.beans.PropertyChangeEvent;
|
||||
import java.beans.PropertyChangeListener;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JProgressBar;
|
||||
import javax.swing.JTextField;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author agreiner
|
||||
*/
|
||||
public class DownloadTaskInformationPanel extends JPanel{
|
||||
|
||||
private JLabel labelTitle;
|
||||
private JLabel labelShow;
|
||||
private JLabel labelSeason;
|
||||
private JLabel labelEpisode;
|
||||
private JLabel labelDuration;
|
||||
private JLabel labelProgress;
|
||||
|
||||
private JTextField textTitle;
|
||||
private JTextField textShow;
|
||||
private JTextField textSeason;
|
||||
private JTextField textEpisode;
|
||||
private JTextField textDuration;
|
||||
private JProgressBar progressBar;
|
||||
|
||||
public DownloadTask selectedDownloadTask;
|
||||
|
||||
public DownloadTaskInformationPanel(){
|
||||
|
||||
labelTitle = new JLabel("Title");
|
||||
labelShow = new JLabel("Show");
|
||||
labelSeason = new JLabel("Season");
|
||||
labelEpisode = new JLabel("Episode");
|
||||
labelDuration = new JLabel("Duration");
|
||||
labelProgress = new JLabel("Progress");
|
||||
|
||||
textTitle = new JTextField();
|
||||
textTitle.setEditable(false);
|
||||
|
||||
textShow = new JTextField();
|
||||
textShow.setEditable(false);
|
||||
|
||||
textSeason = new JTextField();
|
||||
textSeason.setEditable(false);
|
||||
|
||||
textEpisode = new JTextField();
|
||||
textEpisode.setEditable(false);
|
||||
|
||||
textDuration = new JTextField();
|
||||
textDuration.setEditable(false);
|
||||
|
||||
progressBar = new JProgressBar(0, 100);
|
||||
|
||||
setLayout(new GridLayout(6, 2));
|
||||
|
||||
add(labelTitle);
|
||||
add(textTitle);
|
||||
add(labelShow);
|
||||
add(textShow);
|
||||
add(labelSeason);
|
||||
add(textSeason);
|
||||
add(labelEpisode);
|
||||
add(textEpisode);
|
||||
add(labelDuration);
|
||||
add(textDuration);
|
||||
add(labelProgress);
|
||||
add(progressBar);
|
||||
}
|
||||
|
||||
public void clearInformation(){
|
||||
this.selectedDownloadTask = null;
|
||||
textTitle.setText("");
|
||||
textShow.setText("");
|
||||
textSeason.setText("");
|
||||
textEpisode.setText("");
|
||||
textDuration.setText("");
|
||||
progressBar.setValue(0);
|
||||
progressBar.setString("");
|
||||
}
|
||||
|
||||
public void setInformation(DownloadTask downloadTask){
|
||||
textTitle.setText(downloadTask.getEpisodeWrapper().getTitle());
|
||||
textTitle.setEditable(false);
|
||||
textShow.setText(downloadTask.getEpisodeWrapper().getShow());
|
||||
textShow.setEditable(false);
|
||||
textSeason.setText(downloadTask.getEpisodeWrapper().getSeason());
|
||||
textSeason.setEditable(false);
|
||||
textEpisode.setText(downloadTask.getEpisodeWrapper().getEpisode());
|
||||
textEpisode.setEditable(false);
|
||||
textDuration.setText(downloadTask.getEpisodeWrapper().getDuration());
|
||||
|
||||
if(selectedDownloadTask != null && selectedDownloadTask.equals(downloadTask)){
|
||||
progressBar.setValue(downloadTask.percentCompleted);
|
||||
progressBar.setStringPainted(true);
|
||||
String done = FileUtils.byteCountToDisplaySize(downloadTask.totalBytesRead);
|
||||
String todo = FileUtils.byteCountToDisplaySize(downloadTask.fileSize);
|
||||
progressBar.setString(done+"/"+todo);
|
||||
}
|
||||
|
||||
downloadTask.addPropertyChangeListener((PropertyChangeEvent evt) -> {
|
||||
|
||||
if(selectedDownloadTask != null && evt.getPropertyName().equals(Long.toString(selectedDownloadTask.getEpisodeWrapper().getId()))){
|
||||
progressBar.setValue((int)evt.getNewValue());
|
||||
progressBar.setStringPainted(true);
|
||||
String done = FileUtils.byteCountToDisplaySize(downloadTask.totalBytesRead);
|
||||
String todo = FileUtils.byteCountToDisplaySize(downloadTask.fileSize);
|
||||
progressBar.setString(done+"/"+todo);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package com.greinet.tvtotalripper.ui;
|
||||
|
||||
import com.greinet.tvtotalripper.download.DownloadTask;
|
||||
import java.awt.GridLayout;
|
||||
import java.beans.PropertyChangeEvent;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JProgressBar;
|
||||
import javax.swing.JTextField;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author agreiner
|
||||
*/
|
||||
public class DownloadTaskInformationPanel extends JPanel{
|
||||
|
||||
/** The label for the title */
|
||||
private final JLabel labelTitle;
|
||||
/** The label for the show */
|
||||
private final JLabel labelShow;
|
||||
/** The label for the season */
|
||||
private final JLabel labelSeason;
|
||||
/** The label for the episode */
|
||||
private final JLabel labelEpisode;
|
||||
/** The label for the duration */
|
||||
private final JLabel labelDuration;
|
||||
/** The label for the download progress */
|
||||
private final JLabel labelProgress;
|
||||
/** The text field for the title */
|
||||
private final JTextField textTitle;
|
||||
/** The text field for the show */
|
||||
private final JTextField textShow;
|
||||
/** The text field for the season */
|
||||
private final JTextField textSeason;
|
||||
/** The text field for the episode */
|
||||
private final JTextField textEpisode;
|
||||
/** The text field for the duration */
|
||||
private final JTextField textDuration;
|
||||
/** The text field for the download progress */
|
||||
private final JProgressBar progressBar;
|
||||
|
||||
/** The currently visualized download task */
|
||||
public DownloadTask selectedDownloadTask;
|
||||
|
||||
/**
|
||||
* Create a Panel for DownloadTask information visualization
|
||||
*/
|
||||
public DownloadTaskInformationPanel(){
|
||||
|
||||
labelTitle = new JLabel("Title");
|
||||
labelShow = new JLabel("Show");
|
||||
labelSeason = new JLabel("Season");
|
||||
labelEpisode = new JLabel("Episode");
|
||||
labelDuration = new JLabel("Duration");
|
||||
labelProgress = new JLabel("Progress");
|
||||
|
||||
textTitle = new JTextField();
|
||||
textTitle.setEditable(false);
|
||||
|
||||
textShow = new JTextField();
|
||||
textShow.setEditable(false);
|
||||
|
||||
textSeason = new JTextField();
|
||||
textSeason.setEditable(false);
|
||||
|
||||
textEpisode = new JTextField();
|
||||
textEpisode.setEditable(false);
|
||||
|
||||
textDuration = new JTextField();
|
||||
textDuration.setEditable(false);
|
||||
|
||||
progressBar = new JProgressBar(0, 100);
|
||||
|
||||
setLayout(new GridLayout(6, 2));
|
||||
|
||||
add(labelTitle);
|
||||
add(textTitle);
|
||||
add(labelShow);
|
||||
add(textShow);
|
||||
add(labelSeason);
|
||||
add(textSeason);
|
||||
add(labelEpisode);
|
||||
add(textEpisode);
|
||||
add(labelDuration);
|
||||
add(textDuration);
|
||||
add(labelProgress);
|
||||
add(progressBar);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear all information
|
||||
*/
|
||||
public void clearInformation(){
|
||||
this.selectedDownloadTask = null;
|
||||
textTitle.setText("");
|
||||
textShow.setText("");
|
||||
textSeason.setText("");
|
||||
textEpisode.setText("");
|
||||
textDuration.setText("");
|
||||
progressBar.setValue(0);
|
||||
progressBar.setString("");
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the information of the download task
|
||||
* @param downloadTask the download task
|
||||
*/
|
||||
public void setInformation(DownloadTask downloadTask){
|
||||
textTitle.setText(downloadTask.getEpisodeWrapper().getTitle());
|
||||
textTitle.setEditable(false);
|
||||
textShow.setText(downloadTask.getEpisodeWrapper().getShow());
|
||||
textShow.setEditable(false);
|
||||
textSeason.setText(downloadTask.getEpisodeWrapper().getSeason());
|
||||
textSeason.setEditable(false);
|
||||
textEpisode.setText(downloadTask.getEpisodeWrapper().getEpisode());
|
||||
textEpisode.setEditable(false);
|
||||
textDuration.setText(downloadTask.getEpisodeWrapper().getDuration());
|
||||
|
||||
if(selectedDownloadTask != null && selectedDownloadTask.equals(downloadTask)){
|
||||
progressBar.setValue(downloadTask.getPercentCompleted());
|
||||
progressBar.setStringPainted(true);
|
||||
String done = FileUtils.byteCountToDisplaySize(downloadTask.getTotalBytesRead());
|
||||
String todo = FileUtils.byteCountToDisplaySize(downloadTask.getFileSize());
|
||||
progressBar.setString(done+"/"+todo);
|
||||
}
|
||||
|
||||
downloadTask.addPropertyChangeListener((PropertyChangeEvent evt) -> {
|
||||
|
||||
if(selectedDownloadTask != null && evt.getPropertyName().equals(Long.toString(selectedDownloadTask.getEpisodeWrapper().getId()))){
|
||||
progressBar.setValue((int)evt.getNewValue());
|
||||
progressBar.setStringPainted(true);
|
||||
String done = FileUtils.byteCountToDisplaySize(downloadTask.getTotalBytesRead());
|
||||
String todo = FileUtils.byteCountToDisplaySize(downloadTask.getFileSize());
|
||||
progressBar.setString(done+"/"+todo);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,124 +1,146 @@
|
||||
package com.greinet.tvtotalripper.ui;
|
||||
|
||||
import com.greinet.tvtotalripper.crawler.EpisodeWrapper;
|
||||
import java.awt.Color;
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.GridBagLayout;
|
||||
import java.util.List;
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.DefaultListModel;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JList;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.event.ListSelectionEvent;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author agreiner
|
||||
*/
|
||||
public class EpisodesRipperPanel {
|
||||
|
||||
private final JPanel panel;
|
||||
|
||||
private JList<EpisodeWrapper> listPanel;
|
||||
private DefaultListModel<EpisodeWrapper> listModel;
|
||||
|
||||
private JTextField textField;
|
||||
private final JButton buttonDownload;
|
||||
private final JLabel label;
|
||||
private final List<EpisodeWrapper> episodes;
|
||||
|
||||
private final JButton buttonDownloadAll;
|
||||
|
||||
public EpisodesRipperPanel(List<EpisodeWrapper> episodes){
|
||||
this.episodes = episodes;
|
||||
|
||||
panel = new JPanel(false);
|
||||
panel.setLayout(new GridBagLayout());
|
||||
|
||||
GridBagConstraints c = new GridBagConstraints();
|
||||
c.gridx = 0;
|
||||
c.gridy = 0;
|
||||
c.gridwidth = 3;
|
||||
c.fill = GridBagConstraints.BOTH;
|
||||
c.weightx = 0.4;
|
||||
|
||||
textField = new JTextField();
|
||||
textField.setEditable(false);
|
||||
panel.add(textField,c);
|
||||
|
||||
buttonDownload = new JButton("Download");
|
||||
c.gridx = 3;
|
||||
c.gridwidth = 2;
|
||||
c.weightx = 0.1;
|
||||
|
||||
panel.add(buttonDownload,c);
|
||||
|
||||
listModel = new DefaultListModel<>();
|
||||
episodes.forEach(e -> listModel.addElement(e));
|
||||
|
||||
listPanel = new JList<>(listModel);
|
||||
JScrollPane scrollPane = new JScrollPane();
|
||||
scrollPane.setViewportView(listPanel);
|
||||
listPanel.setLayoutOrientation(JList.VERTICAL);
|
||||
listPanel.setSelectedIndex(0);
|
||||
|
||||
listPanel.addListSelectionListener((ListSelectionEvent e) -> {
|
||||
textField.setText(listPanel.getSelectedValue().toString());
|
||||
});
|
||||
textField.setText(listPanel.getSelectedValue().toString());
|
||||
|
||||
c.gridx = 0;
|
||||
c.gridy = 1;
|
||||
c.gridwidth = 5;
|
||||
c.gridheight = 5;
|
||||
c.weightx = 0.5;
|
||||
|
||||
panel.add(scrollPane,c);
|
||||
|
||||
label = new JLabel(Integer.toString(episodes.size()));
|
||||
label.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
|
||||
|
||||
buttonDownloadAll = new JButton("Download all episodes");
|
||||
c.gridx = 6;
|
||||
c.gridy = 0;
|
||||
c.gridwidth = 1;
|
||||
c.gridheight = 6;
|
||||
c.weightx = 0.5;
|
||||
panel.add(buttonDownloadAll,c);
|
||||
|
||||
|
||||
|
||||
c.gridx = 4;
|
||||
c.gridy = 6;
|
||||
c.gridwidth = 1;
|
||||
c.gridheight = 1;
|
||||
c.fill = GridBagConstraints.NONE;
|
||||
c.anchor = GridBagConstraints.EAST;
|
||||
|
||||
panel.add(label, c);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
public JPanel getJPanel(){
|
||||
return panel;
|
||||
}
|
||||
|
||||
public EpisodeWrapper getCurrentSelected(){
|
||||
return listPanel.getSelectedValue();
|
||||
}
|
||||
|
||||
public JButton getDownloadButton(){
|
||||
return buttonDownload;
|
||||
}
|
||||
|
||||
public JButton getDownloadAllButton(){
|
||||
return buttonDownloadAll;
|
||||
}
|
||||
|
||||
}
|
||||
package com.greinet.tvtotalripper.ui;
|
||||
|
||||
import com.greinet.tvtotalripper.crawler.EpisodeWrapper;
|
||||
import java.awt.Color;
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.GridBagLayout;
|
||||
import java.util.List;
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.DefaultListModel;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JList;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.event.ListSelectionEvent;
|
||||
|
||||
/**
|
||||
* A panel to display the episodes of a season
|
||||
*/
|
||||
public class EpisodesRipperPanel {
|
||||
/** The JPanel */
|
||||
private final JPanel panel;
|
||||
/** The list for the episodes */
|
||||
private JList<EpisodeWrapper> listPanel;
|
||||
/** The list model for the episode list */
|
||||
private DefaultListModel<EpisodeWrapper> listModel;
|
||||
/** The text field for the currently selected episode */
|
||||
private JTextField textField;
|
||||
/** The button to start the episode download */
|
||||
private final JButton buttonDownload;
|
||||
/** The label for the episode count */
|
||||
private final JLabel label;
|
||||
/** The list of episodes */
|
||||
private final List<EpisodeWrapper> episodes;
|
||||
/** The button to download all episodes in the list */
|
||||
private final JButton buttonDownloadAll;
|
||||
|
||||
/**
|
||||
* Create a panel to display episodes in a list
|
||||
* @param episodes the episodes to display
|
||||
*/
|
||||
public EpisodesRipperPanel(List<EpisodeWrapper> episodes){
|
||||
this.episodes = episodes;
|
||||
|
||||
panel = new JPanel(false);
|
||||
panel.setLayout(new GridBagLayout());
|
||||
|
||||
GridBagConstraints c = new GridBagConstraints();
|
||||
c.gridx = 0;
|
||||
c.gridy = 0;
|
||||
c.gridwidth = 3;
|
||||
c.fill = GridBagConstraints.BOTH;
|
||||
c.weightx = 0.4;
|
||||
|
||||
textField = new JTextField();
|
||||
textField.setEditable(false);
|
||||
panel.add(textField,c);
|
||||
|
||||
buttonDownload = new JButton("Download");
|
||||
c.gridx = 3;
|
||||
c.gridwidth = 2;
|
||||
c.weightx = 0.1;
|
||||
|
||||
panel.add(buttonDownload,c);
|
||||
|
||||
listModel = new DefaultListModel<>();
|
||||
episodes.forEach(e -> listModel.addElement(e));
|
||||
|
||||
listPanel = new JList<>(listModel);
|
||||
JScrollPane scrollPane = new JScrollPane();
|
||||
scrollPane.setViewportView(listPanel);
|
||||
listPanel.setLayoutOrientation(JList.VERTICAL);
|
||||
listPanel.setSelectedIndex(0);
|
||||
|
||||
listPanel.addListSelectionListener((ListSelectionEvent e) -> {
|
||||
textField.setText(listPanel.getSelectedValue().toString());
|
||||
});
|
||||
textField.setText(listPanel.getSelectedValue().toString());
|
||||
|
||||
c.gridx = 0;
|
||||
c.gridy = 1;
|
||||
c.gridwidth = 5;
|
||||
c.gridheight = 5;
|
||||
c.weightx = 0.5;
|
||||
|
||||
panel.add(scrollPane,c);
|
||||
|
||||
label = new JLabel(Integer.toString(episodes.size()));
|
||||
label.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
|
||||
|
||||
buttonDownloadAll = new JButton("Download all episodes");
|
||||
c.gridx = 6;
|
||||
c.gridy = 0;
|
||||
c.gridwidth = 1;
|
||||
c.gridheight = 6;
|
||||
c.weightx = 0.5;
|
||||
panel.add(buttonDownloadAll,c);
|
||||
|
||||
|
||||
|
||||
c.gridx = 4;
|
||||
c.gridy = 6;
|
||||
c.gridwidth = 1;
|
||||
c.gridheight = 1;
|
||||
c.fill = GridBagConstraints.NONE;
|
||||
c.anchor = GridBagConstraints.EAST;
|
||||
|
||||
panel.add(label, c);
|
||||
|
||||
|
||||
|
||||
}
|
||||
/**
|
||||
* Get the JPanel
|
||||
* @return the JPanel
|
||||
*/
|
||||
public JPanel getJPanel(){
|
||||
return panel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the currently selecte episode
|
||||
* @return
|
||||
*/
|
||||
public EpisodeWrapper getCurrentSelected(){
|
||||
return listPanel.getSelectedValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the download button
|
||||
* @return the download button
|
||||
*/
|
||||
public JButton getDownloadButton(){
|
||||
return buttonDownload;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the download all button
|
||||
* @return the download all button
|
||||
*/
|
||||
public JButton getDownloadAllButton(){
|
||||
return buttonDownloadAll;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,132 +1,153 @@
|
||||
package com.greinet.tvtotalripper.ui;
|
||||
|
||||
import com.greinet.tvtotalripper.crawler.CrawlerUtil;
|
||||
import com.greinet.tvtotalripper.crawler.EpisodeWrapper;
|
||||
import com.greinet.tvtotalripper.download.DownloadTask;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JTabbedPane;
|
||||
import org.openqa.selenium.By;
|
||||
import org.openqa.selenium.WebElement;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author agreiner
|
||||
*/
|
||||
public class RipperWindow {
|
||||
|
||||
private final JFrame frame;
|
||||
private final JTabbedPane tabbedPane;
|
||||
|
||||
private JComponent panel1;
|
||||
private JComponent panel2;
|
||||
private JComponent panel3;
|
||||
private JComponent panel4;
|
||||
private JComponent panel5;
|
||||
|
||||
private BaseRipperPanel showRipperPanel;
|
||||
private SettingsRipperPanel srp;
|
||||
private DownloadRipperPanel drp;
|
||||
|
||||
public RipperWindow(){
|
||||
frame = new JFrame("TV Total Ripper");
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
|
||||
tabbedPane = new JTabbedPane();
|
||||
|
||||
showRipperPanel = createShowsPanel();
|
||||
srp = new SettingsRipperPanel();
|
||||
drp = new DownloadRipperPanel();
|
||||
|
||||
panel1 = showRipperPanel.getJPanel();
|
||||
panel2 = new JPanel();
|
||||
panel3 = new JPanel();
|
||||
panel4 = drp.getJPanel();
|
||||
panel5 = srp.getPanel();
|
||||
|
||||
tabbedPane.addTab("Shows", panel1);
|
||||
tabbedPane.addTab("Seasons", panel2);
|
||||
tabbedPane.addTab("Episodes", panel3);
|
||||
tabbedPane.addTab("Downloads", panel4);
|
||||
tabbedPane.addTab("Settings", panel5);
|
||||
|
||||
tabbedPane.setEnabledAt(1, false);
|
||||
tabbedPane.setEnabledAt(2, false);
|
||||
|
||||
tabbedPane.setPreferredSize(new Dimension(900, 400));
|
||||
|
||||
frame.add(tabbedPane);
|
||||
|
||||
frame.pack();
|
||||
frame.setAlwaysOnTop(true);
|
||||
frame.setVisible(true);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
RipperWindow ripperWindow = new RipperWindow();
|
||||
}
|
||||
|
||||
private BaseRipperPanel createShowsPanel(){
|
||||
List<WebElement> shows = CrawlerUtil.getShows();
|
||||
Map<String, String> namesToUrls = shows.stream().collect(Collectors.toMap(e -> e.findElement(By.xpath(".//img")).getAttribute("alt") , e -> e.getAttribute("href")));
|
||||
|
||||
BaseRipperPanel brp = new BaseRipperPanel(namesToUrls);
|
||||
|
||||
brp.getJButton().addActionListener((ActionEvent e) -> {
|
||||
panel3 = new JPanel();
|
||||
tabbedPane.setEnabledAt(2, false);
|
||||
panel1 = createSeasonsPanel(brp.getCurrentSelected()).getJPanel();
|
||||
tabbedPane.setComponentAt(1, panel1);
|
||||
tabbedPane.setEnabledAt(1, true);
|
||||
tabbedPane.setSelectedIndex(1);
|
||||
});
|
||||
|
||||
return brp;
|
||||
}
|
||||
|
||||
private BaseRipperPanel createSeasonsPanel(String url){
|
||||
List<WebElement> seasons = CrawlerUtil.getSeasons(url);
|
||||
Map<String, String> elements = seasons.stream().collect(Collectors.toMap(e -> e.getText(), e -> e.getText()));
|
||||
|
||||
BaseRipperPanel brp = new BaseRipperPanel(elements);
|
||||
|
||||
brp.getJButton().addActionListener((ActionEvent e) -> {
|
||||
tabbedPane.setEnabledAt(2, false);
|
||||
panel2 = createEpisodesPanel(url,brp.getCurrentSelected()).getJPanel();
|
||||
tabbedPane.setComponentAt(2, panel2);
|
||||
tabbedPane.setEnabledAt(2, true);
|
||||
tabbedPane.setSelectedIndex(2);
|
||||
});
|
||||
|
||||
return brp;
|
||||
}
|
||||
|
||||
private EpisodesRipperPanel createEpisodesPanel(String url, String seasonName){
|
||||
List<EpisodeWrapper> episodes = CrawlerUtil.getEpisodes(url, seasonName);
|
||||
|
||||
EpisodesRipperPanel erp = new EpisodesRipperPanel(episodes);
|
||||
|
||||
erp.getDownloadButton().addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
drp.addTask(new DownloadTask(erp.getCurrentSelected()));
|
||||
}
|
||||
});
|
||||
|
||||
erp.getDownloadAllButton().addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
episodes.forEach(d -> drp.addTask(new DownloadTask(d)));
|
||||
}
|
||||
});
|
||||
return erp;
|
||||
}
|
||||
|
||||
package com.greinet.tvtotalripper.ui;
|
||||
|
||||
import com.greinet.tvtotalripper.crawler.CrawlerUtil;
|
||||
import com.greinet.tvtotalripper.crawler.EpisodeWrapper;
|
||||
import com.greinet.tvtotalripper.download.DownloadTask;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JTabbedPane;
|
||||
import org.openqa.selenium.By;
|
||||
import org.openqa.selenium.WebElement;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author agreiner
|
||||
*/
|
||||
public class RipperWindow {
|
||||
/** The pane managing the tabs */
|
||||
private final JTabbedPane tabbedPane;
|
||||
/** The panel for the shows */
|
||||
private JComponent panel1;
|
||||
/** The panel for the seasons */
|
||||
private JComponent panel2;
|
||||
/** The panel for the episodes */
|
||||
private JComponent panel3;
|
||||
/** The panel for the downloads */
|
||||
private final JComponent panel4;
|
||||
/** The panel for the settings */
|
||||
private final JComponent panel5;
|
||||
/** The show panel */
|
||||
private final BaseRipperPanel showRipperPanel;
|
||||
/** The settings panel */
|
||||
private final SettingsRipperPanel srp;
|
||||
/** The downloads panel */
|
||||
private final DownloadRipperPanel drp;
|
||||
|
||||
/**
|
||||
* Create the main application UI
|
||||
*/
|
||||
public RipperWindow(){
|
||||
JFrame frame = new JFrame("TV Total Ripper");
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
|
||||
tabbedPane = new JTabbedPane();
|
||||
|
||||
showRipperPanel = createShowsPanel();
|
||||
srp = new SettingsRipperPanel();
|
||||
drp = new DownloadRipperPanel();
|
||||
|
||||
panel1 = showRipperPanel.getJPanel();
|
||||
panel2 = new JPanel();
|
||||
panel3 = new JPanel();
|
||||
panel4 = drp.getJPanel();
|
||||
panel5 = srp.getPanel();
|
||||
|
||||
tabbedPane.addTab("Shows", panel1);
|
||||
tabbedPane.addTab("Seasons", panel2);
|
||||
tabbedPane.addTab("Episodes", panel3);
|
||||
tabbedPane.addTab("Downloads", panel4);
|
||||
tabbedPane.addTab("Settings", panel5);
|
||||
|
||||
tabbedPane.setEnabledAt(1, false);
|
||||
tabbedPane.setEnabledAt(2, false);
|
||||
|
||||
tabbedPane.setPreferredSize(new Dimension(900, 400));
|
||||
|
||||
frame.add(tabbedPane);
|
||||
|
||||
frame.pack();
|
||||
frame.setAlwaysOnTop(true);
|
||||
frame.setVisible(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* The main method to start the program
|
||||
* @param args the arguments
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
RipperWindow ripperWindow = new RipperWindow();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a show panel listing all available shows
|
||||
* @return the shopw panel
|
||||
*/
|
||||
private BaseRipperPanel createShowsPanel(){
|
||||
List<WebElement> shows = CrawlerUtil.getShows();
|
||||
Map<String, String> namesToUrls = shows.stream().collect(Collectors.toMap(e -> e.findElement(By.xpath(".//img")).getAttribute("alt") , e -> e.getAttribute("href")));
|
||||
|
||||
BaseRipperPanel brp = new BaseRipperPanel(namesToUrls);
|
||||
|
||||
brp.getJButton().addActionListener((ActionEvent e) -> {
|
||||
panel3 = new JPanel();
|
||||
tabbedPane.setEnabledAt(2, false);
|
||||
panel1 = createSeasonsPanel(brp.getCurrentSelected()).getJPanel();
|
||||
tabbedPane.setComponentAt(1, panel1);
|
||||
tabbedPane.setEnabledAt(1, true);
|
||||
tabbedPane.setSelectedIndex(1);
|
||||
});
|
||||
|
||||
return brp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a seaon panel for a selected show
|
||||
* @param url the URL to the show
|
||||
* @return the season panel
|
||||
*/
|
||||
private BaseRipperPanel createSeasonsPanel(String url){
|
||||
List<WebElement> seasons = CrawlerUtil.getSeasons(url);
|
||||
Map<String, String> elements = seasons.stream().collect(Collectors.toMap(e -> e.getText(), e -> e.getText()));
|
||||
|
||||
BaseRipperPanel brp = new BaseRipperPanel(elements);
|
||||
|
||||
brp.getJButton().addActionListener((ActionEvent e) -> {
|
||||
tabbedPane.setEnabledAt(2, false);
|
||||
panel2 = createEpisodesPanel(url,brp.getCurrentSelected()).getJPanel();
|
||||
tabbedPane.setComponentAt(2, panel2);
|
||||
tabbedPane.setEnabledAt(2, true);
|
||||
tabbedPane.setSelectedIndex(2);
|
||||
});
|
||||
|
||||
return brp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a episode panel
|
||||
* @param url the URL to the episode list
|
||||
* @param seasonName the name of the selected season
|
||||
* @return the episode panel
|
||||
*/
|
||||
private EpisodesRipperPanel createEpisodesPanel(String url, String seasonName){
|
||||
List<EpisodeWrapper> episodes = CrawlerUtil.getEpisodes(url, seasonName);
|
||||
|
||||
EpisodesRipperPanel erp = new EpisodesRipperPanel(episodes);
|
||||
|
||||
erp.getDownloadButton().addActionListener((ActionEvent e) -> {
|
||||
drp.addTask(new DownloadTask(erp.getCurrentSelected()));
|
||||
});
|
||||
|
||||
erp.getDownloadAllButton().addActionListener((ActionEvent e) -> {
|
||||
episodes.forEach(d -> drp.addTask(new DownloadTask(d)));
|
||||
});
|
||||
return erp;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,90 +1,97 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package com.greinet.tvtotalripper.ui;
|
||||
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Font;
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.GridBagLayout;
|
||||
import java.io.File;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFileChooser;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author agreiner
|
||||
*/
|
||||
public class SettingsRipperPanel {
|
||||
|
||||
private JPanel panel;
|
||||
private JLabel labelDownloadFolder;
|
||||
private JTextField textDownloadFolder;
|
||||
private JFileChooser fileChooserDownloadFolder;
|
||||
public static File DOWNLOADFOLDER = new File(".");
|
||||
private JButton button;
|
||||
|
||||
public SettingsRipperPanel(){
|
||||
panel = new JPanel();
|
||||
panel.setLayout(new GridBagLayout());
|
||||
|
||||
GridBagConstraints gbc = new GridBagConstraints();
|
||||
gbc.anchor = GridBagConstraints.NORTHWEST;
|
||||
|
||||
gbc.gridx=0;
|
||||
gbc.gridy=0;
|
||||
gbc.gridwidth=1;
|
||||
gbc.insets.bottom = 10;
|
||||
labelDownloadFolder = new JLabel("Download folder");
|
||||
labelDownloadFolder.setFont(new Font(labelDownloadFolder.getFont().getFontName(), Font.BOLD, 15));
|
||||
panel.add(labelDownloadFolder, gbc);
|
||||
|
||||
gbc.gridx=0;
|
||||
gbc.gridy=1;
|
||||
gbc.gridwidth=8;
|
||||
gbc.insets.left = 20;
|
||||
textDownloadFolder = new JTextField(DOWNLOADFOLDER.getAbsolutePath());
|
||||
textDownloadFolder.setEditable(false);
|
||||
textDownloadFolder.setPreferredSize(new Dimension(500, 30));
|
||||
panel.add(textDownloadFolder,gbc);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
gbc.gridx=8;
|
||||
gbc.gridy=1;
|
||||
gbc.gridwidth=1;
|
||||
gbc.insets.left = 0;
|
||||
button = new JButton("...");
|
||||
panel.add(button,gbc);
|
||||
|
||||
fileChooserDownloadFolder = new JFileChooser(DOWNLOADFOLDER);
|
||||
fileChooserDownloadFolder.setDialogTitle("Select download folder");
|
||||
fileChooserDownloadFolder.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
|
||||
fileChooserDownloadFolder.setAcceptAllFileFilterUsed(false);
|
||||
|
||||
|
||||
button.addActionListener(e -> {
|
||||
int value = fileChooserDownloadFolder.showOpenDialog(panel);
|
||||
|
||||
if (value == JFileChooser.APPROVE_OPTION){
|
||||
DOWNLOADFOLDER = fileChooserDownloadFolder.getSelectedFile();
|
||||
textDownloadFolder.setText(DOWNLOADFOLDER.getAbsolutePath());
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
public JPanel getPanel() {
|
||||
return panel;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package com.greinet.tvtotalripper.ui;
|
||||
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Font;
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.GridBagLayout;
|
||||
import java.io.File;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFileChooser;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author agreiner
|
||||
*/
|
||||
public class SettingsRipperPanel {
|
||||
|
||||
/** The JPanel to visualize the settings */
|
||||
private JPanel panel;
|
||||
/** The JLabel for the download folder selection */
|
||||
private final JLabel labelDownloadFolder;
|
||||
/** The text field for the current download folder */
|
||||
private JTextField textDownloadFolder;
|
||||
/** The file chooser to select the download folder */
|
||||
private JFileChooser fileChooserDownloadFolder;
|
||||
/** The download folder */
|
||||
public static File DOWNLOADFOLDER = new File(".");
|
||||
/** The JButton to open the file chooser dialog */
|
||||
private final JButton button;
|
||||
|
||||
/**
|
||||
* Create a settings panel
|
||||
*/
|
||||
public SettingsRipperPanel(){
|
||||
panel = new JPanel();
|
||||
panel.setLayout(new GridBagLayout());
|
||||
|
||||
GridBagConstraints gbc = new GridBagConstraints();
|
||||
gbc.anchor = GridBagConstraints.NORTHWEST;
|
||||
|
||||
gbc.gridx=0;
|
||||
gbc.gridy=0;
|
||||
gbc.gridwidth=1;
|
||||
gbc.insets.bottom = 10;
|
||||
labelDownloadFolder = new JLabel("Download folder");
|
||||
labelDownloadFolder.setFont(new Font(labelDownloadFolder.getFont().getFontName(), Font.BOLD, 15));
|
||||
panel.add(labelDownloadFolder, gbc);
|
||||
|
||||
gbc.gridx=0;
|
||||
gbc.gridy=1;
|
||||
gbc.gridwidth=8;
|
||||
gbc.insets.left = 20;
|
||||
textDownloadFolder = new JTextField(DOWNLOADFOLDER.getAbsolutePath());
|
||||
textDownloadFolder.setEditable(false);
|
||||
textDownloadFolder.setPreferredSize(new Dimension(500, 30));
|
||||
panel.add(textDownloadFolder,gbc);
|
||||
|
||||
gbc.gridx=8;
|
||||
gbc.gridy=1;
|
||||
gbc.gridwidth=1;
|
||||
gbc.insets.left = 0;
|
||||
button = new JButton("...");
|
||||
panel.add(button,gbc);
|
||||
|
||||
fileChooserDownloadFolder = new JFileChooser(DOWNLOADFOLDER);
|
||||
fileChooserDownloadFolder.setDialogTitle("Select download folder");
|
||||
fileChooserDownloadFolder.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
|
||||
fileChooserDownloadFolder.setAcceptAllFileFilterUsed(false);
|
||||
|
||||
|
||||
button.addActionListener(e -> {
|
||||
int value = fileChooserDownloadFolder.showOpenDialog(panel);
|
||||
|
||||
if (value == JFileChooser.APPROVE_OPTION){
|
||||
DOWNLOADFOLDER = fileChooserDownloadFolder.getSelectedFile();
|
||||
textDownloadFolder.setText(DOWNLOADFOLDER.getAbsolutePath());
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the JPanel
|
||||
* @return the JPanel
|
||||
*/
|
||||
public JPanel getPanel() {
|
||||
return panel;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user