Merge branch 'next' into dev/image
[Sone.git] / src / main / java / net / pterodactylus / sone / core / CoreListenerManager.java
1 /*
2  * Sone - CoreListenerManager.java - Copyright © 2010 David Roden
3  *
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.
8  *
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.
13  *
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/>.
16  */
17
18 package net.pterodactylus.sone.core;
19
20 import net.pterodactylus.sone.data.Image;
21 import net.pterodactylus.sone.data.Post;
22 import net.pterodactylus.sone.data.Reply;
23 import net.pterodactylus.sone.data.Sone;
24 import net.pterodactylus.util.event.AbstractListenerManager;
25 import net.pterodactylus.util.version.Version;
26
27 /**
28  * Manager for {@link CoreListener}s.
29  *
30  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
31  */
32 public class CoreListenerManager extends AbstractListenerManager<Core, CoreListener> {
33
34         /**
35          * Creates a new core listener manager.
36          *
37          * @param source
38          *            The Core
39          */
40         public CoreListenerManager(Core source) {
41                 super(source);
42         }
43
44         //
45         // ACTIONS
46         //
47
48         /**
49          * Notifies all listeners that a new Sone has been discovered.
50          *
51          * @see CoreListener#newSoneFound(Sone)
52          * @param sone
53          *            The discovered sone
54          */
55         void fireNewSoneFound(Sone sone) {
56                 for (CoreListener coreListener : getListeners()) {
57                         coreListener.newSoneFound(sone);
58                 }
59         }
60
61         /**
62          * Notifies all listeners that a new post has been found.
63          *
64          * @see CoreListener#newPostFound(Post)
65          * @param post
66          *            The new post
67          */
68         void fireNewPostFound(Post post) {
69                 for (CoreListener coreListener : getListeners()) {
70                         coreListener.newPostFound(post);
71                 }
72         }
73
74         /**
75          * Notifies all listeners that a new reply has been found.
76          *
77          * @see CoreListener#newReplyFound(Reply)
78          * @param reply
79          *            The new reply
80          */
81         void fireNewReplyFound(Reply reply) {
82                 for (CoreListener coreListener : getListeners()) {
83                         coreListener.newReplyFound(reply);
84                 }
85         }
86
87         /**
88          * Notifies all listeners that the given Sone is now marked as known.
89          *
90          * @see CoreListener#markSoneKnown(Sone)
91          * @param sone
92          *            The known Sone
93          */
94         void fireMarkSoneKnown(Sone sone) {
95                 for (CoreListener coreListener : getListeners()) {
96                         coreListener.markSoneKnown(sone);
97                 }
98         }
99
100         /**
101          * Notifies all listeners that the given post is now marked as known.
102          *
103          * @param post
104          *            The known post
105          */
106         void fireMarkPostKnown(Post post) {
107                 for (CoreListener coreListener : getListeners()) {
108                         coreListener.markPostKnown(post);
109                 }
110         }
111
112         /**
113          * Notifies all listeners that the given reply is now marked as known.
114          *
115          * @param reply
116          *            The known reply
117          */
118         void fireMarkReplyKnown(Reply reply) {
119                 for (CoreListener coreListener : getListeners()) {
120                         coreListener.markReplyKnown(reply);
121                 }
122         }
123
124         /**
125          * Notifies all listener that the given Sone was removed.
126          *
127          * @see CoreListener#soneRemoved(Sone)
128          * @param sone
129          *            The removed Sone
130          */
131         void fireSoneRemoved(Sone sone) {
132                 for (CoreListener coreListener : getListeners()) {
133                         coreListener.soneRemoved(sone);
134                 }
135         }
136
137         /**
138          * Notifies all listener that the given post was removed.
139          *
140          * @see CoreListener#postRemoved(Post)
141          * @param post
142          *            The removed post
143          */
144         void firePostRemoved(Post post) {
145                 for (CoreListener coreListener : getListeners()) {
146                         coreListener.postRemoved(post);
147                 }
148         }
149
150         /**
151          * Notifies all listener that the given reply was removed.
152          *
153          * @see CoreListener#replyRemoved(Reply)
154          * @param reply
155          *            The removed reply
156          */
157         void fireReplyRemoved(Reply reply) {
158                 for (CoreListener coreListener : getListeners()) {
159                         coreListener.replyRemoved(reply);
160                 }
161         }
162
163         /**
164          * Notifies all listeners that the given Sone was locked.
165          *
166          * @see CoreListener#soneLocked(Sone)
167          * @param sone
168          *            The Sone that was locked
169          */
170         void fireSoneLocked(Sone sone) {
171                 for (CoreListener coreListener : getListeners()) {
172                         coreListener.soneLocked(sone);
173                 }
174         }
175
176         /**
177          * Notifies all listeners that the given Sone was unlocked.
178          *
179          * @see CoreListener#soneUnlocked(Sone)
180          * @param sone
181          *            The Sone that was unlocked
182          */
183         void fireSoneUnlocked(Sone sone) {
184                 for (CoreListener coreListener : getListeners()) {
185                         coreListener.soneUnlocked(sone);
186                 }
187         }
188
189         /**
190          * Notifies all listeners that the insert of the given Sone has started.
191          *
192          * @see SoneInsertListener#insertStarted(Sone)
193          * @param sone
194          *            The Sone being inserted
195          */
196         void fireSoneInserting(Sone sone) {
197                 for (CoreListener coreListener : getListeners()) {
198                         coreListener.soneInserting(sone);
199                 }
200         }
201
202         /**
203          * Notifies all listeners that the insert of the given Sone has finished
204          * successfully.
205          *
206          * @see SoneInsertListener#insertFinished(Sone, long)
207          * @param sone
208          *            The Sone that was inserted
209          * @param insertDuration
210          *            The insert duration (in milliseconds)
211          */
212         void fireSoneInserted(Sone sone, long insertDuration) {
213                 for (CoreListener coreListener : getListeners()) {
214                         coreListener.soneInserted(sone, insertDuration);
215                 }
216         }
217
218         /**
219          * Notifies all listeners that the insert of the given Sone was aborted.
220          *
221          * @see SoneInsertListener#insertStarted(Sone)
222          * @param sone
223          *            The Sone being inserted
224          * @param cause
225          *            The cause for the abortion (may be {@code null}
226          */
227         void fireSoneInsertAborted(Sone sone, Throwable cause) {
228                 for (CoreListener coreListener : getListeners()) {
229                         coreListener.soneInsertAborted(sone, cause);
230                 }
231         }
232
233         /**
234          * Notifies all listeners that a new version was found.
235          *
236          * @see CoreListener#updateFound(Version, long, long)
237          * @param version
238          *            The new version
239          * @param releaseTime
240          *            The release time of the new version
241          * @param latestEdition
242          *            The latest edition of the Sone homepage
243          */
244         void fireUpdateFound(Version version, long releaseTime, long latestEdition) {
245                 for (CoreListener coreListener : getListeners()) {
246                         coreListener.updateFound(version, releaseTime, latestEdition);
247                 }
248         }
249
250         /**
251          * Notifies all listeners that an image has started being inserted.
252          *
253          * @see CoreListener#imageInsertStarted(Image)
254          * @param image
255          *            The image that is now inserted
256          */
257         void fireImageInsertStarted(Image image) {
258                 for (CoreListener coreListener : getListeners()) {
259                         coreListener.imageInsertStarted(image);
260                 }
261         }
262
263         /**
264          * Notifies all listeners that an image insert was aborted by the user.
265          *
266          * @see CoreListener#imageInsertAborted(Image)
267          * @param image
268          *            The image that is not inserted anymore
269          */
270         void fireImageInsertAborted(Image image) {
271                 for (CoreListener coreListener : getListeners()) {
272                         coreListener.imageInsertAborted(image);
273                 }
274         }
275
276         /**
277          * Notifies all listeners that an image was successfully inserted.
278          *
279          * @see CoreListener#imageInsertFinished(Image)
280          * @param image
281          *            The image that was inserted
282          */
283         void fireImageInsertFinished(Image image) {
284                 for (CoreListener coreListener : getListeners()) {
285                         coreListener.imageInsertFinished(image);
286                 }
287         }
288
289         /**
290          * Notifies all listeners that an image failed to be inserted.
291          *
292          * @see CoreListener#imageInsertFailed(Image, Throwable)
293          * @param image
294          *            The image that could not be inserted
295          * @param cause
296          *            The cause of the failure
297          */
298         void fireImageInsertFailed(Image image, Throwable cause) {
299                 for (CoreListener coreListener : getListeners()) {
300                         coreListener.imageInsertFailed(image, cause);
301                 }
302         }
303
304 }