From 06c97e457ce62ff258d85e6cfb9b4d94f9e9147f 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:56:11 +0100 Subject: [PATCH] =?utf8?q?Convert=20=E2=80=9Cimage=20insert=20aborted?= =?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/ImageInsertAbortedEvent.java | 39 ++++++++++++++++++++++ .../net/pterodactylus/sone/web/WebInterface.java | 20 ++++++----- 5 files changed, 53 insertions(+), 30 deletions(-) create mode 100644 src/main/java/net/pterodactylus/sone/core/event/ImageInsertAbortedEvent.java diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index f47b76b..51a831c 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -35,6 +35,7 @@ import java.util.logging.Logger; 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.ImageInsertStartedEvent; import net.pterodactylus.sone.core.event.MarkPostKnownEvent; import net.pterodactylus.sone.core.event.MarkPostReplyKnownEvent; @@ -2505,7 +2506,7 @@ public class Core extends AbstractService implements IdentityListener, UpdateLis @Override public void imageInsertAborted(Image image) { logger.log(Level.WARNING, String.format("Image insert aborted for %s.", image)); - coreListenerManager.fireImageInsertAborted(image); + eventBus.post(new ImageInsertAbortedEvent(image)); } /** diff --git a/src/main/java/net/pterodactylus/sone/core/CoreListener.java b/src/main/java/net/pterodactylus/sone/core/CoreListener.java index 9bc8c0c..55833c0 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 insert was aborted by the user. - * - * @param image - * The image that is not inserted anymore - */ - public void imageInsertAborted(Image image); - - /** * Notifies a listener that an image was successfully 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 55853c9..d409dac 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 aborted. + * + * @author David ‘Bombe’ Roden + */ +public class ImageInsertAbortedEvent extends ImageEvent { + + /** + * Creates a new “image insert aborted” event. + * + * @param image + * The image whose insert aborted + */ + public ImageInsertAbortedEvent(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 a30508e..dfc0b25 100644 --- a/src/main/java/net/pterodactylus/sone/web/WebInterface.java +++ b/src/main/java/net/pterodactylus/sone/web/WebInterface.java @@ -37,6 +37,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.ImageInsertStartedEvent; import net.pterodactylus.sone.core.event.MarkPostKnownEvent; import net.pterodactylus.sone.core.event.MarkPostReplyKnownEvent; @@ -1049,18 +1050,21 @@ public class WebInterface implements CoreListener { notificationManager.addNotification(insertingImagesNotification); } - // - // CORELISTENER METHODS - // - /** - * {@inheritDoc} + * Notifies the web interface that an {@link Image} insert was aborted. + * + * @param imageInsertAbortedEvent + * The event */ - @Override - public void imageInsertAborted(Image image) { - insertingImagesNotification.remove(image); + @Subscribe + public void imageInsertAborted(ImageInsertAbortedEvent imageInsertAbortedEvent) { + insertingImagesNotification.remove(imageInsertAbortedEvent.image()); } + // + // CORELISTENER METHODS + // + /** * {@inheritDoc} */ -- 2.7.4