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 the given post is now marked as known.
54 void fireMarkPostKnown(Post post) {
55 for (CoreListener coreListener : getListeners()) {
56 coreListener.markPostKnown(post);
61 * Notifies all listeners that the given reply is now marked as known.
66 void fireMarkReplyKnown(PostReply reply) {
67 for (CoreListener coreListener : getListeners()) {
68 coreListener.markReplyKnown(reply);
73 * Notifies all listener that the given Sone was removed.
75 * @see CoreListener#soneRemoved(Sone)
79 void fireSoneRemoved(Sone sone) {
80 for (CoreListener coreListener : getListeners()) {
81 coreListener.soneRemoved(sone);
86 * Notifies all listener that the given post was removed.
88 * @see CoreListener#postRemoved(Post)
92 void firePostRemoved(Post post) {
93 for (CoreListener coreListener : getListeners()) {
94 coreListener.postRemoved(post);
99 * Notifies all listener that the given reply was removed.
101 * @see CoreListener#replyRemoved(PostReply)
105 void fireReplyRemoved(PostReply reply) {
106 for (CoreListener coreListener : getListeners()) {
107 coreListener.replyRemoved(reply);
112 * Notifies all listeners that the given Sone was locked.
114 * @see CoreListener#soneLocked(Sone)
116 * The Sone that was locked
118 void fireSoneLocked(Sone sone) {
119 for (CoreListener coreListener : getListeners()) {
120 coreListener.soneLocked(sone);
125 * Notifies all listeners that the given Sone was unlocked.
127 * @see CoreListener#soneUnlocked(Sone)
129 * The Sone that was unlocked
131 void fireSoneUnlocked(Sone sone) {
132 for (CoreListener coreListener : getListeners()) {
133 coreListener.soneUnlocked(sone);
138 * Notifies all listeners that the insert of the given Sone has started.
140 * @see SoneInsertListener#insertStarted(Sone)
142 * The Sone being inserted
144 void fireSoneInserting(Sone sone) {
145 for (CoreListener coreListener : getListeners()) {
146 coreListener.soneInserting(sone);
151 * Notifies all listeners that the insert of the given Sone has finished
154 * @see SoneInsertListener#insertFinished(Sone, long)
156 * The Sone that was inserted
157 * @param insertDuration
158 * The insert duration (in milliseconds)
160 void fireSoneInserted(Sone sone, long insertDuration) {
161 for (CoreListener coreListener : getListeners()) {
162 coreListener.soneInserted(sone, insertDuration);
167 * Notifies all listeners that the insert of the given Sone was aborted.
169 * @see SoneInsertListener#insertStarted(Sone)
171 * The Sone being inserted
173 * The cause for the abortion (may be {@code null}
175 void fireSoneInsertAborted(Sone sone, Throwable cause) {
176 for (CoreListener coreListener : getListeners()) {
177 coreListener.soneInsertAborted(sone, cause);
182 * Notifies all listeners that a new version was found.
184 * @see CoreListener#updateFound(Version, long, long)
188 * The release time of the new version
189 * @param latestEdition
190 * The latest edition of the Sone homepage
192 void fireUpdateFound(Version version, long releaseTime, long latestEdition) {
193 for (CoreListener coreListener : getListeners()) {
194 coreListener.updateFound(version, releaseTime, latestEdition);
199 * Notifies all listeners that an image has started being inserted.
201 * @see CoreListener#imageInsertStarted(Image)
203 * The image that is now inserted
205 void fireImageInsertStarted(Image image) {
206 for (CoreListener coreListener : getListeners()) {
207 coreListener.imageInsertStarted(image);
212 * Notifies all listeners that an image insert was aborted by the user.
214 * @see CoreListener#imageInsertAborted(Image)
216 * The image that is not inserted anymore
218 void fireImageInsertAborted(Image image) {
219 for (CoreListener coreListener : getListeners()) {
220 coreListener.imageInsertAborted(image);
225 * Notifies all listeners that an image was successfully inserted.
227 * @see CoreListener#imageInsertFinished(Image)
229 * The image that was inserted
231 void fireImageInsertFinished(Image image) {
232 for (CoreListener coreListener : getListeners()) {
233 coreListener.imageInsertFinished(image);
238 * Notifies all listeners that an image failed to be inserted.
240 * @see CoreListener#imageInsertFailed(Image, Throwable)
242 * The image that could not be inserted
244 * The cause of the failure
246 void fireImageInsertFailed(Image image, Throwable cause) {
247 for (CoreListener coreListener : getListeners()) {
248 coreListener.imageInsertFailed(image, cause);