From 9cecd5e7a697c86c892961745dad21d019b7b9ba Mon Sep 17 00:00:00 2001 From: yukihane Date: Sat, 27 Aug 2011 13:56:41 +0900 Subject: [PATCH] =?utf8?q?worker=20listener=E3=81=AE=E3=82=A4=E3=83=B3?= =?utf8?q?=E3=82=BF=E3=83=95=E3=82=A7=E3=83=BC=E3=82=B9=E5=90=8D=E5=A4=89?= =?utf8?q?=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- frontend/src/saccubus/worker/Convert.java | 2 +- frontend/src/saccubus/worker/Download.java | 2 +- frontend/src/saccubus/worker/Worker.java | 35 ++++++++++++++++++++++ frontend/src/yukihane/inqubus/gui/MainFrame.java | 6 ++-- frontend/src/yukihane/inqubus/manager/Request.java | 14 ++++----- 5 files changed, 47 insertions(+), 12 deletions(-) create mode 100644 frontend/src/saccubus/worker/Worker.java diff --git a/frontend/src/saccubus/worker/Convert.java b/frontend/src/saccubus/worker/Convert.java index f87102e..c01cff6 100644 --- a/frontend/src/saccubus/worker/Convert.java +++ b/frontend/src/saccubus/worker/Convert.java @@ -50,7 +50,7 @@ public class Convert extends Worker { * @param output 変換後出力動画. * @throws IOException 変換失敗. */ - public Convert(ConvertProfile profile, File video, File comment, SaccubusListener listener) { + public Convert(ConvertProfile profile, File video, File comment, WorkerListener listener) { super(listener); this.profile = profile; this.videoFile = video; diff --git a/frontend/src/saccubus/worker/Download.java b/frontend/src/saccubus/worker/Download.java index c2044fe..9480486 100644 --- a/frontend/src/saccubus/worker/Download.java +++ b/frontend/src/saccubus/worker/Download.java @@ -49,7 +49,7 @@ public class Download extends Worker { * @param listener * @param flag */ - public Download(DownloadProfile profile, String videoId, SaccubusListener listener) { + public Download(DownloadProfile profile, String videoId, WorkerListener listener) { // TODO listener登録 super(listener); this.videoId = videoId; diff --git a/frontend/src/saccubus/worker/Worker.java b/frontend/src/saccubus/worker/Worker.java new file mode 100644 index 0000000..7ff7250 --- /dev/null +++ b/frontend/src/saccubus/worker/Worker.java @@ -0,0 +1,35 @@ +package saccubus.worker; + +import java.util.concurrent.Callable; + +/** + * 途中経過を報告できるCallableです. + * + * @author yuki + */ +public abstract class Worker implements Callable { + private static int serialNumber = 0; + + private final int id; + private final WorkerListener listener; + + public Worker(WorkerListener listener) { + this.id = ++serialNumber; + this.listener = listener; + } + + public final int getId() { + return id; + } + + protected final void publish(V value) { + if (listener != null) { + listener.process(value); + } + } + + public interface WorkerListener { + + void process(V progress); + } +} diff --git a/frontend/src/yukihane/inqubus/gui/MainFrame.java b/frontend/src/yukihane/inqubus/gui/MainFrame.java index e3a2dd1..6d2144b 100644 --- a/frontend/src/yukihane/inqubus/gui/MainFrame.java +++ b/frontend/src/yukihane/inqubus/gui/MainFrame.java @@ -51,7 +51,7 @@ import saccubus.MainFrame_AboutBox; import saccubus.util.WayBackTimeParser; import saccubus.worker.ConvertProgress; import saccubus.worker.DownloadProgress; -import saccubus.worker.Worker.SaccubusListener; +import saccubus.worker.Worker.WorkerListener; import saccubus.worker.profile.CommentProfile; import saccubus.worker.profile.DownloadProfile; import saccubus.worker.profile.GeneralProfile; @@ -578,7 +578,7 @@ public class MainFrame extends JFrame { return menuBar; } - private class DownloadProgressListener implements SaccubusListener { + private class DownloadProgressListener implements WorkerListener { @Override public void process(DownloadProgress progress) { @@ -586,7 +586,7 @@ public class MainFrame extends JFrame { } } - private class ConvertProgressListener implements SaccubusListener { + private class ConvertProgressListener implements WorkerListener { @Override public void process(ConvertProgress progress) { diff --git a/frontend/src/yukihane/inqubus/manager/Request.java b/frontend/src/yukihane/inqubus/manager/Request.java index fd26eba..5abb30f 100644 --- a/frontend/src/yukihane/inqubus/manager/Request.java +++ b/frontend/src/yukihane/inqubus/manager/Request.java @@ -3,7 +3,7 @@ package yukihane.inqubus.manager; import java.io.File; import saccubus.worker.ConvertProgress; import saccubus.worker.DownloadProgress; -import saccubus.worker.Worker.SaccubusListener; +import saccubus.worker.Worker.WorkerListener; import saccubus.worker.profile.ConvertProfile; import saccubus.worker.profile.DownloadProfile; @@ -17,12 +17,12 @@ public class Request { private final int rowId; private final DownloadProfile downloadProfile; private final String videoId; - private final SaccubusListener downloadProgressListener; + private final WorkerListener downloadProgressListener; private final ConvertProfile convertProfile; - private final SaccubusListener convertProgressListener; + private final WorkerListener convertProgressListener; - public Request(DownloadProfile download, String videoId, SaccubusListener downListener, - ConvertProfile convert, SaccubusListener convListener) { + public Request(DownloadProfile download, String videoId, WorkerListener downListener, + ConvertProfile convert, WorkerListener convListener) { this.rowId = ++serialId; this.downloadProfile = download; this.videoId = videoId; @@ -47,11 +47,11 @@ public class Request { return rowId; } - SaccubusListener getDownloadProgressListener() { + WorkerListener getDownloadProgressListener() { return downloadProgressListener; } - SaccubusListener getConvertProgressListener() { + WorkerListener getConvertProgressListener() { return convertProgressListener; } } -- 2.11.0