Remove/Clear queue option (right-click menu)

This commit is contained in:
4pr0n 2015-12-20 11:58:37 -08:00
parent e968b0e155
commit 5018d80b51
3 changed files with 86 additions and 6 deletions

View File

@ -9,7 +9,6 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
import javax.swing.DefaultListModel;
import org.apache.commons.cli.BasicParser; import org.apache.commons.cli.BasicParser;
import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.CommandLine;
@ -19,21 +18,21 @@ import org.apache.commons.cli.ParseException;
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.ui.MainWindow;
import com.rarchives.ripme.ui.History; import com.rarchives.ripme.ui.History;
import com.rarchives.ripme.ui.HistoryEntry; import com.rarchives.ripme.ui.HistoryEntry;
import com.rarchives.ripme.ui.MainWindow;
import com.rarchives.ripme.ui.UpdateUtils; import com.rarchives.ripme.ui.UpdateUtils;
import com.rarchives.ripme.utils.Utils;
import com.rarchives.ripme.utils.RipUtils; import com.rarchives.ripme.utils.RipUtils;
import com.rarchives.ripme.utils.Utils;
/** /**
* * Entry point to application.
* Decides to display UI or to run silently via command-line.
*/ */
public class App { public class App {
public static Logger logger; public static Logger logger;
private static final History HISTORY = new History(); private static final History HISTORY = new History();
private static DefaultListModel queueListModel;
public static void main(String[] args) throws MalformedURLException { public static void main(String[] args) throws MalformedURLException {
Utils.configureLogger(); Utils.configureLogger();

View File

@ -110,7 +110,7 @@ public class MainWindow implements Runnable, RipStatusHandler {
historyButtonRerip; historyButtonRerip;
// Queue // Queue
private static JButton optionQueue; public static JButton optionQueue;
private static JPanel queuePanel; private static JPanel queuePanel;
private static JList queueList; private static JList queueList;
private static DefaultListModel queueListModel; private static DefaultListModel queueListModel;
@ -396,6 +396,7 @@ public class MainWindow implements Runnable, RipStatusHandler {
queueListModel = new DefaultListModel(); queueListModel = new DefaultListModel();
queueList = new JList(queueListModel); queueList = new JList(queueListModel);
queueList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); queueList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
queueList.addMouseListener(new QueueMenuMouseListener());
queueListScroll = new JScrollPane(queueList, queueListScroll = new JScrollPane(queueList,
JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);

View File

@ -0,0 +1,80 @@
package com.rarchives.ripme.ui;
import java.awt.event.ActionEvent;
import java.awt.event.InputEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.Enumeration;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.DefaultListModel;
import javax.swing.JList;
import javax.swing.JPopupMenu;
import com.rarchives.ripme.utils.Utils;
public class QueueMenuMouseListener extends MouseAdapter {
private JPopupMenu popup = new JPopupMenu();
private Action removeSelected,
clearQueue;
private JList queueList;
private DefaultListModel queueListModel;
@SuppressWarnings("serial")
public QueueMenuMouseListener() {
removeSelected = new AbstractAction("Remove Selected") {
@Override
public void actionPerformed(ActionEvent ae) {
Object o = queueList.getSelectedValue();
while (o != null) {
queueListModel.removeElement(o);
o = queueList.getSelectedValue();
}
updateUI();
}
};
popup.add(removeSelected);
clearQueue = new AbstractAction("Remove All") {
@Override
public void actionPerformed(ActionEvent ae) {
queueListModel.removeAllElements();
updateUI();
}
};
popup.add(clearQueue);
}
private void updateUI() {
Utils.setConfigList("queue", (Enumeration<Object>) queueListModel.elements());
if (queueListModel.size() == 0) {
MainWindow.optionQueue.setText("Queue");
}
else {
MainWindow.optionQueue.setText("Queue (" + queueListModel.size() + ")");
}
}
@Override
public void mouseClicked(MouseEvent e) {
if (e.getModifiers() == InputEvent.BUTTON3_MASK) {
if (!(e.getSource() instanceof JList)) {
return;
}
queueList = (JList) e.getSource();
queueListModel = (DefaultListModel) queueList.getModel();
queueList.requestFocus();
int nx = e.getX();
if (nx > 500) {
nx = nx - popup.getSize().width;
}
popup.show(e.getComponent(), nx, e.getY() - popup.getSize().height);
}
}
}