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 reply is now marked as known.
54 void fireMarkReplyKnown(PostReply reply) {
55 for (CoreListener coreListener : getListeners()) {
56 coreListener.markReplyKnown(reply);
61 * Notifies all listener that the given Sone was removed.
63 * @see CoreListener#soneRemoved(Sone)
67 void fireSoneRemoved(Sone sone) {
68 for (CoreListener coreListener : getListeners()) {
69 coreListener.soneRemoved(sone);
74 * Notifies all listener that the given post was removed.
76 * @see CoreListener#postRemoved(Post)
80 void firePostRemoved(Post post) {
81 for (CoreListener coreListener : getListeners()) {
82 coreListener.postRemoved(post);
87 * Notifies all listener that the given reply was removed.
89 * @see CoreListener#replyRemoved(PostReply)
93 void fireReplyRemoved(PostReply reply) {
94 for (CoreListener coreListener : getListeners()) {
95 coreListener.replyRemoved(reply);
100 * Notifies all listeners that the given Sone was locked.
102 * @see CoreListener#soneLocked(Sone)
104 * The Sone that was locked
106 void fireSoneLocked(Sone sone) {
107 for (CoreListener coreListener : getListeners()) {
108 coreListener.soneLocked(sone);
113 * Notifies all listeners that the given Sone was unlocked.
115 * @see CoreListener#soneUnlocked(Sone)
117 * The Sone that was unlocked
119 void fireSoneUnlocked(Sone sone) {
120 for (CoreListener coreListener : getListeners()) {
121 coreListener.soneUnlocked(sone);
126 * Notifies all listeners that the insert of the given Sone has started.
128 * @see SoneInsertListener#insertStarted(Sone)
130 * The Sone being inserted
132 void fireSoneInserting(Sone sone) {
133 for (CoreListener coreListener : getListeners()) {
134 coreListener.soneInserting(sone);
139 * Notifies all listeners that the insert of the given Sone has finished
142 * @see SoneInsertListener#insertFinished(Sone, long)
144 * The Sone that was inserted
145 * @param insertDuration
146 * The insert duration (in milliseconds)
148 void fireSoneInserted(Sone sone, long insertDuration) {
149 for (CoreListener coreListener : getListeners()) {
150 coreListener.soneInserted(sone, insertDuration);
155 * Notifies all listeners that the insert of the given Sone was aborted.
157 * @see SoneInsertListener#insertStarted(Sone)
159 * The Sone being inserted
161 * The cause for the abortion (may be {@code null}
163 void fireSoneInsertAborted(Sone sone, Throwable cause) {
164 for (CoreListener coreListener : getListeners()) {
165 coreListener.soneInsertAborted(sone, cause);
170 * Notifies all listeners that a new version was found.
172 * @see CoreListener#updateFound(Version, long, long)
176 * The release time of the new version
177 * @param latestEdition
178 * The latest edition of the Sone homepage
180 void fireUpdateFound(Version version, long releaseTime, long latestEdition) {
181 for (CoreListener coreListener : getListeners()) {
182 coreListener.updateFound(version, releaseTime, latestEdition);
187 * Notifies all listeners that an image has started being inserted.
189 * @see CoreListener#imageInsertStarted(Image)
191 * The image that is now inserted
193 void fireImageInsertStarted(Image image) {
194 for (CoreListener coreListener : getListeners()) {
195 coreListener.imageInsertStarted(image);
200 * Notifies all listeners that an image insert was aborted by the user.
202 * @see CoreListener#imageInsertAborted(Image)
204 * The image that is not inserted anymore
206 void fireImageInsertAborted(Image image) {
207 for (CoreListener coreListener : getListeners()) {
208 coreListener.imageInsertAborted(image);
213 * Notifies all listeners that an image was successfully inserted.
215 * @see CoreListener#imageInsertFinished(Image)
217 * The image that was inserted
219 void fireImageInsertFinished(Image image) {
220 for (CoreListener coreListener : getListeners()) {
221 coreListener.imageInsertFinished(image);
226 * Notifies all listeners that an image failed to be inserted.
228 * @see CoreListener#imageInsertFailed(Image, Throwable)
230 * The image that could not be inserted
232 * The cause of the failure
234 void fireImageInsertFailed(Image image, Throwable cause) {
235 for (CoreListener coreListener : getListeners()) {
236 coreListener.imageInsertFailed(image, cause);