From 7dcc372f1b36d978db02f29f9494ed73032ba922 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Wed, 16 Jan 2013 21:58:49 +0100 Subject: [PATCH] =?utf8?q?Convert=20=E2=80=9Cimage=20insert=20finished?= =?utf8?q?=E2=80=9D=20into=20EventBus-based=20event.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../java/net/pterodactylus/sone/core/Core.java | 3 +- .../net/pterodactylus/sone/core/CoreListener.java | 8 ----- .../sone/core/CoreListenerManager.java | 13 -------- .../sone/core/event/ImageInsertFinishedEvent.java | 39 ++++++++++++++++++++++ .../net/pterodactylus/sone/web/WebInterface.java | 22 +++++++----- 5 files changed, 54 insertions(+), 31 deletions(-) create mode 100644 src/main/java/net/pterodactylus/sone/core/event/ImageInsertFinishedEvent.java diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index 51a831c..c40fd0f 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -36,6 +36,7 @@ import net.pterodactylus.sone.core.Options.DefaultOption; import net.pterodactylus.sone.core.Options.Option; import net.pterodactylus.sone.core.Options.OptionWatcher; import net.pterodactylus.sone.core.event.ImageInsertAbortedEvent; +import net.pterodactylus.sone.core.event.ImageInsertFinishedEvent; import net.pterodactylus.sone.core.event.ImageInsertStartedEvent; import net.pterodactylus.sone.core.event.MarkPostKnownEvent; import net.pterodactylus.sone.core.event.MarkPostReplyKnownEvent; @@ -2518,7 +2519,7 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis image.setKey(key.toString()); deleteTemporaryImage(image.getId()); touchConfiguration(); - coreListenerManager.fireImageInsertFinished(image); + eventBus.post(new ImageInsertFinishedEvent(image)); } /** diff --git a/src/main/java/net/pterodactylus/sone/core/CoreListener.java b/src/main/java/net/pterodactylus/sone/core/CoreListener.java index 55833c0..a449293 100644 --- a/src/main/java/net/pterodactylus/sone/core/CoreListener.java +++ b/src/main/java/net/pterodactylus/sone/core/CoreListener.java @@ -30,14 +30,6 @@ import net.pterodactylus.sone.data.Image; public interface CoreListener extends EventListener { /** - * Notifies a listener that an image was successfully inserted. - * - * @param image - * The image that was inserted - */ - public void imageInsertFinished(Image image); - - /** * Notifies a listener that an image failed to be inserted. * * @param image diff --git a/src/main/java/net/pterodactylus/sone/core/CoreListenerManager.java b/src/main/java/net/pterodactylus/sone/core/CoreListenerManager.java index d409dac..47738b3 100644 --- a/src/main/java/net/pterodactylus/sone/core/CoreListenerManager.java +++ b/src/main/java/net/pterodactylus/sone/core/CoreListenerManager.java @@ -42,19 +42,6 @@ public class CoreListenerManager extends AbstractListenerManager. + */ + +package net.pterodactylus.sone.core.event; + +import net.pterodactylus.sone.data.Image; + +/** + * Event that signals that an {@link Image} insert is finished. + * + * @author David ‘Bombe’ Roden + */ +public class ImageInsertFinishedEvent extends ImageEvent { + + /** + * Creates a new “image insert finished” event. + * + * @param image + * The image whose insert finished + */ + public ImageInsertFinishedEvent(Image image) { + super(image); + } + +} diff --git a/src/main/java/net/pterodactylus/sone/web/WebInterface.java b/src/main/java/net/pterodactylus/sone/web/WebInterface.java index dfc0b25..9f0e8d9 100644 --- a/src/main/java/net/pterodactylus/sone/web/WebInterface.java +++ b/src/main/java/net/pterodactylus/sone/web/WebInterface.java @@ -38,6 +38,7 @@ import java.util.logging.Logger; import net.pterodactylus.sone.core.Core; import net.pterodactylus.sone.core.CoreListener; import net.pterodactylus.sone.core.event.ImageInsertAbortedEvent; +import net.pterodactylus.sone.core.event.ImageInsertFinishedEvent; import net.pterodactylus.sone.core.event.ImageInsertStartedEvent; import net.pterodactylus.sone.core.event.MarkPostKnownEvent; import net.pterodactylus.sone.core.event.MarkPostReplyKnownEvent; @@ -1061,20 +1062,23 @@ public class WebInterface implements CoreListener { insertingImagesNotification.remove(imageInsertAbortedEvent.image()); } - // - // CORELISTENER METHODS - // - /** - * {@inheritDoc} + * Notifies the web interface that an {@link Image} insert is finished. + * + * @param imageInsertFinishedEvent + * The event */ - @Override - public void imageInsertFinished(Image image) { - insertingImagesNotification.remove(image); - insertedImagesNotification.add(image); + @Subscribe + public void imageInsertFinished(ImageInsertFinishedEvent imageInsertFinishedEvent) { + insertingImagesNotification.remove(imageInsertFinishedEvent.image()); + insertedImagesNotification.add(imageInsertFinishedEvent.image()); notificationManager.addNotification(insertedImagesNotification); } + // + // CORELISTENER METHODS + // + /** * {@inheritDoc} */ -- 2.7.4