2 * Sone - CoreListenerManager.java - Copyright © 2010–2012 David Roden
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 package net.pterodactylus.sone.core;
20 import net.pterodactylus.sone.data.Image;
21 import net.pterodactylus.sone.data.Post;
22 import net.pterodactylus.sone.data.PostReply;
23 import net.pterodactylus.sone.data.Sone;
24 import net.pterodactylus.util.event.AbstractListenerManager;
25 import net.pterodactylus.util.version.Version;
28 * Manager for {@link CoreListener}s.
30 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
32 public class CoreListenerManager extends AbstractListenerManager<Core, CoreListener> {
35 * Creates a new core listener manager.
40 public CoreListenerManager(Core source) {
49 * Notifies all listeners that a new Sone has been discovered.
51 * @see CoreListener#newSoneFound(Sone)
55 void fireNewSoneFound(Sone sone) {
56 for (CoreListener coreListener : getListeners()) {
57 coreListener.newSoneFound(sone);
62 * Notifies all listeners that a new post has been found.
64 * @see CoreListener#newPostFound(Post)
68 void fireNewPostFound(Post post) {
69 for (CoreListener coreListener : getListeners()) {
70 coreListener.newPostFound(post);
75 * Notifies all listeners that a new reply has been found.
77 * @see CoreListener#newReplyFound(PostReply)
81 void fireNewReplyFound(PostReply reply) {
82 for (CoreListener coreListener : getListeners()) {
83 coreListener.newReplyFound(reply);
88 * Notifies all listeners that the given Sone is now marked as known.
90 * @see CoreListener#markSoneKnown(Sone)
94 void fireMarkSoneKnown(Sone sone) {
95 for (CoreListener coreListener : getListeners()) {
96 coreListener.markSoneKnown(sone);
101 * Notifies all listeners that the given post is now marked as known.
106 void fireMarkPostKnown(Post post) {
107 for (CoreListener coreListener : getListeners()) {
108 coreListener.markPostKnown(post);
113 * Notifies all listeners that the given reply is now marked as known.
118 void fireMarkReplyKnown(PostReply reply) {
119 for (CoreListener coreListener : getListeners()) {
120 coreListener.markReplyKnown(reply);
125 * Notifies all listener that the given Sone was removed.
127 * @see CoreListener#soneRemoved(Sone)
131 void fireSoneRemoved(Sone sone) {
132 for (CoreListener coreListener : getListeners()) {
133 coreListener.soneRemoved(sone);
138 * Notifies all listener that the given post was removed.
140 * @see CoreListener#postRemoved(Post)
144 void firePostRemoved(Post post) {
145 for (CoreListener coreListener : getListeners()) {
146 coreListener.postRemoved(post);
151 * Notifies all listener that the given reply was removed.
153 * @see CoreListener#replyRemoved(PostReply)
157 void fireReplyRemoved(PostReply reply) {
158 for (CoreListener coreListener : getListeners()) {
159 coreListener.replyRemoved(reply);
164 * Notifies all listeners that the given Sone was locked.
166 * @see CoreListener#soneLocked(Sone)
168 * The Sone that was locked
170 void fireSoneLocked(Sone sone) {
171 for (CoreListener coreListener : getListeners()) {
172 coreListener.soneLocked(sone);
177 * Notifies all listeners that the given Sone was unlocked.
179 * @see CoreListener#soneUnlocked(Sone)
181 * The Sone that was unlocked
183 void fireSoneUnlocked(Sone sone) {
184 for (CoreListener coreListener : getListeners()) {
185 coreListener.soneUnlocked(sone);
190 * Notifies all listeners that the insert of the given Sone has started.
192 * @see SoneInsertListener#insertStarted(Sone)
194 * The Sone being inserted
196 void fireSoneInserting(Sone sone) {
197 for (CoreListener coreListener : getListeners()) {
198 coreListener.soneInserting(sone);
203 * Notifies all listeners that the insert of the given Sone has finished
206 * @see SoneInsertListener#insertFinished(Sone, long)
208 * The Sone that was inserted
209 * @param insertDuration
210 * The insert duration (in milliseconds)
212 void fireSoneInserted(Sone sone, long insertDuration) {
213 for (CoreListener coreListener : getListeners()) {
214 coreListener.soneInserted(sone, insertDuration);
219 * Notifies all listeners that the insert of the given Sone was aborted.
221 * @see SoneInsertListener#insertStarted(Sone)
223 * The Sone being inserted
225 * The cause for the abortion (may be {@code null}
227 void fireSoneInsertAborted(Sone sone, Throwable cause) {
228 for (CoreListener coreListener : getListeners()) {
229 coreListener.soneInsertAborted(sone, cause);
234 * Notifies all listeners that a new version was found.
236 * @see CoreListener#updateFound(Version, long, long)
240 * The release time of the new version
241 * @param latestEdition
242 * The latest edition of the Sone homepage
244 void fireUpdateFound(Version version, long releaseTime, long latestEdition) {
245 for (CoreListener coreListener : getListeners()) {
246 coreListener.updateFound(version, releaseTime, latestEdition);
251 * Notifies all listeners that an image has started being inserted.
253 * @see CoreListener#imageInsertStarted(Image)
255 * The image that is now inserted
257 void fireImageInsertStarted(Image image) {
258 for (CoreListener coreListener : getListeners()) {
259 coreListener.imageInsertStarted(image);
264 * Notifies all listeners that an image insert was aborted by the user.
266 * @see CoreListener#imageInsertAborted(Image)
268 * The image that is not inserted anymore
270 void fireImageInsertAborted(Image image) {
271 for (CoreListener coreListener : getListeners()) {
272 coreListener.imageInsertAborted(image);
277 * Notifies all listeners that an image was successfully inserted.
279 * @see CoreListener#imageInsertFinished(Image)
281 * The image that was inserted
283 void fireImageInsertFinished(Image image) {
284 for (CoreListener coreListener : getListeners()) {
285 coreListener.imageInsertFinished(image);
290 * Notifies all listeners that an image failed to be inserted.
292 * @see CoreListener#imageInsertFailed(Image, Throwable)
294 * The image that could not be inserted
296 * The cause of the failure
298 void fireImageInsertFailed(Image image, Throwable cause) {
299 for (CoreListener coreListener : getListeners()) {
300 coreListener.imageInsertFailed(image, cause);