125 lines
3.3 KiB
Java
125 lines
3.3 KiB
Java
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;
|
|
}
|
|
|
|
}
|