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 reply has been found.
51 * @see CoreListener#newReplyFound(PostReply)
55 void fireNewReplyFound(PostReply reply) {
56 for (CoreListener coreListener : getListeners()) {
57 coreListener.newReplyFound(reply);
62 * Notifies all listeners that the given Sone is now marked as known.
64 * @see CoreListener#markSoneKnown(Sone)
68 void fireMarkSoneKnown(Sone sone) {
69 for (CoreListener coreListener : getListeners()) {
70 coreListener.markSoneKnown(sone);
75 * Notifies all listeners that the given post is now marked as known.
80 void fireMarkPostKnown(Post post) {
81 for (CoreListener coreListener : getListeners()) {
82 coreListener.markPostKnown(post);
87 * Notifies all listeners that the given reply is now marked as known.
92 void fireMarkReplyKnown(PostReply reply) {
93 for (CoreListener coreListener : getListeners()) {
94 coreListener.markReplyKnown(reply);
99 * Notifies all listener that the given Sone was removed.
101 * @see CoreListener#soneRemoved(Sone)
105 void fireSoneRemoved(Sone sone) {
106 for (CoreListener coreListener : getListeners()) {
107 coreListener.soneRemoved(sone);
112 * Notifies all listener that the given post was removed.
114 * @see CoreListener#postRemoved(Post)
118 void firePostRemoved(Post post) {
119 for (CoreListener coreListener : getListeners()) {
120 coreListener.postRemoved(post);
125 * Notifies all listener that the given reply was removed.
127 * @see CoreListener#replyRemoved(PostReply)
131 void fireReplyRemoved(PostReply reply) {
132 for (CoreListener coreListener : getListeners()) {
133 coreListener.replyRemoved(reply);
138 * Notifies all listeners that the given Sone was locked.
140 * @see CoreListener#soneLocked(Sone)
142 * The Sone that was locked
144 void fireSoneLocked(Sone sone) {
145 for (CoreListener coreListener : getListeners()) {
146 coreListener.soneLocked(sone);
151 * Notifies all listeners that the given Sone was unlocked.
153 * @see CoreListener#soneUnlocked(Sone)
155 * The Sone that was unlocked
157 void fireSoneUnlocked(Sone sone) {
158 for (CoreListener coreListener : getListeners()) {
159 coreListener.soneUnlocked(sone);
164 * Notifies all listeners that the insert of the given Sone has started.
166 * @see SoneInsertListener#insertStarted(Sone)
168 * The Sone being inserted
170 void fireSoneInserting(Sone sone) {
171 for (CoreListener coreListener : getListeners()) {
172 coreListener.soneInserting(sone);
177 * Notifies all listeners that the insert of the given Sone has finished
180 * @see SoneInsertListener#insertFinished(Sone, long)
182 * The Sone that was inserted
183 * @param insertDuration
184 * The insert duration (in milliseconds)
186 void fireSoneInserted(Sone sone, long insertDuration) {
187 for (CoreListener coreListener : getListeners()) {
188 coreListener.soneInserted(sone, insertDuration);
193 * Notifies all listeners that the insert of the given Sone was aborted.
195 * @see SoneInsertListener#insertStarted(Sone)
197 * The Sone being inserted
199 * The cause for the abortion (may be {@code null}
201 void fireSoneInsertAborted(Sone sone, Throwable cause) {
202 for (CoreListener coreListener : getListeners()) {
203 coreListener.soneInsertAborted(sone, cause);
208 * Notifies all listeners that a new version was found.
210 * @see CoreListener#updateFound(Version, long, long)
214 * The release time of the new version
215 * @param latestEdition
216 * The latest edition of the Sone homepage
218 void fireUpdateFound(Version version, long releaseTime, long latestEdition) {
219 for (CoreListener coreListener : getListeners()) {
220 coreListener.updateFound(version, releaseTime, latestEdition);
225 * Notifies all listeners that an image has started being inserted.
227 * @see CoreListener#imageInsertStarted(Image)
229 * The image that is now inserted
231 void fireImageInsertStarted(Image image) {
232 for (CoreListener coreListener : getListeners()) {
233 coreListener.imageInsertStarted(image);
238 * Notifies all listeners that an image insert was aborted by the user.
240 * @see CoreListener#imageInsertAborted(Image)
242 * The image that is not inserted anymore
244 void fireImageInsertAborted(Image image) {
245 for (CoreListener coreListener : getListeners()) {
246 coreListener.imageInsertAborted(image);
251 * Notifies all listeners that an image was successfully inserted.
253 * @see CoreListener#imageInsertFinished(Image)
255 * The image that was inserted
257 void fireImageInsertFinished(Image image) {
258 for (CoreListener coreListener : getListeners()) {
259 coreListener.imageInsertFinished(image);
264 * Notifies all listeners that an image failed to be inserted.
266 * @see CoreListener#imageInsertFailed(Image, Throwable)
268 * The image that could not be inserted
270 * The cause of the failure
272 void fireImageInsertFailed(Image image, Throwable cause) {
273 for (CoreListener coreListener : getListeners()) {
274 coreListener.imageInsertFailed(image, cause);