Add cancel button to queue monitor
This commit is contained in:
BIN
resources/uk/co/majenko/audiobookrecorder/icons/close.png
Normal file
BIN
resources/uk/co/majenko/audiobookrecorder/icons/close.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.1 KiB |
@@ -42,4 +42,5 @@ public class Icons {
|
|||||||
static public final ImageIcon tooltip = new ImageIcon(Icons.class.getResource("icons/tooltip.png"));
|
static public final ImageIcon tooltip = new ImageIcon(Icons.class.getResource("icons/tooltip.png"));
|
||||||
static public final ImageIcon queued = new ImageIcon(Icons.class.getResource("icons/queued.png"));
|
static public final ImageIcon queued = new ImageIcon(Icons.class.getResource("icons/queued.png"));
|
||||||
static public final ImageIcon processing = new ImageIcon(Icons.class.getResource("icons/processing.png"));
|
static public final ImageIcon processing = new ImageIcon(Icons.class.getResource("icons/processing.png"));
|
||||||
|
static public final ImageIcon close = new ImageIcon(Icons.class.getResource("icons/close.png"));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,15 +7,18 @@ import java.awt.Graphics;
|
|||||||
import java.awt.Rectangle;
|
import java.awt.Rectangle;
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
|
import java.awt.event.MouseEvent;
|
||||||
|
import java.awt.event.MouseListener;
|
||||||
|
|
||||||
public class QueueMonitor extends JPanel {
|
public class QueueMonitor extends JPanel implements MouseListener {
|
||||||
|
|
||||||
ArrayList<WorkerThread> threadList = new ArrayList<WorkerThread>();
|
ArrayList<WorkerThread> threadList = new ArrayList<WorkerThread>();
|
||||||
Queue queue;
|
Queue<Runnable> queue;
|
||||||
|
|
||||||
public QueueMonitor(Queue q) {
|
public QueueMonitor(Queue<Runnable> q) {
|
||||||
super();
|
super();
|
||||||
queue = q;
|
queue = q;
|
||||||
|
addMouseListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addThread(WorkerThread t) {
|
public void addThread(WorkerThread t) {
|
||||||
@@ -23,15 +26,22 @@ public class QueueMonitor extends JPanel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void purgeQueue() {
|
public void purgeQueue() {
|
||||||
|
Runnable work;
|
||||||
synchronized (queue) {
|
synchronized (queue) {
|
||||||
queue.clear();
|
while (queue.size() > 0) {
|
||||||
|
work = queue.remove();
|
||||||
|
if (work instanceof SentenceJob) {
|
||||||
|
SentenceJob sj = (SentenceJob)work;
|
||||||
|
sj.setDequeued();
|
||||||
|
}
|
||||||
|
}
|
||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Dimension getPreferredSize() {
|
public Dimension getPreferredSize() {
|
||||||
return new Dimension(100 + (24 * threadList.size()), 24);
|
return new Dimension(150 + (24 * threadList.size()), 24);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -65,6 +75,35 @@ public class QueueMonitor extends JPanel {
|
|||||||
|
|
||||||
g.setColor(getForeground());
|
g.setColor(getForeground());
|
||||||
g.drawString("Queued: " + queue.size(), threadList.size() * 24 + 4, 16);
|
g.drawString("Queued: " + queue.size(), threadList.size() * 24 + 4, 16);
|
||||||
|
|
||||||
|
if (queue.size() > 0) {
|
||||||
|
Icons.close.paintIcon(this, g, size.width - 23, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseEntered(MouseEvent evt) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseExited(MouseEvent evt) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mousePressed(MouseEvent evt) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseReleased(MouseEvent evt) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseClicked(MouseEvent evt) {
|
||||||
|
if (queue.size() == 0) return; // No button - ignore it
|
||||||
|
Dimension size = getPreferredSize();
|
||||||
|
if (evt.getX() > (size.width - 24)) {
|
||||||
|
purgeQueue();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user