ed3a6f0d8f57e0cde1b00adb8c75ac5fe126d063
[Sone.git] / src / main / java / net / pterodactylus / sone / core / CoreListenerManager.java
1 /*
2  * Sone - CoreListenerManager.java - Copyright © 2010–2012 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.PostReply;
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 the given reply is now marked as known.
50          *
51          * @param reply
52          *            The known reply
53          */
54         void fireMarkReplyKnown(PostReply reply) {
55                 for (CoreListener coreListener : getListeners()) {
56                         coreListener.markReplyKnown(reply);
57                 }
58         }
59
60         /**
61          * Notifies all listener that the given Sone was removed.
62          *
63          * @see CoreListener#soneRemoved(Sone)
64          * @param sone
65          *            The removed Sone
66          */
67         void fireSoneRemoved(Sone sone) {
68                 for (CoreListener coreListener : getListeners()) {
69                         coreListener.soneRemoved(sone);
70                 }
71         }
72
73         /**
74          * Notifies all listener that the given post was removed.
75          *
76          * @see CoreListener#postRemoved(Post)
77          * @param post
78          *            The removed post
79          */
80         void firePostRemoved(Post post) {
81                 for (CoreListener coreListener : getListeners()) {
82                         coreListener.postRemoved(post);
83                 }
84         }
85
86         /**
87          * Notifies all listener that the given reply was removed.
88          *
89          * @see CoreListener#replyRemoved(PostReply)
90          * @param reply
91          *            The removed reply
92          */
93         void fireReplyRemoved(PostReply reply) {
94                 for (CoreListener coreListener : getListeners()) {
95                         coreListener.replyRemoved(reply);
96                 }
97         }
98
99         /**
100          * Notifies all listeners that the given Sone was locked.
101          *
102          * @see CoreListener#soneLocked(Sone)
103          * @param sone
104          *            The Sone that was locked
105          */
106         void fireSoneLocked(Sone sone) {
107                 for (CoreListener coreListener : getListeners()) {
108                         coreListener.soneLocked(sone);
109                 }
110         }
111
112         /**
113          * Notifies all listeners that the given Sone was unlocked.
114          *
115          * @see CoreListener#soneUnlocked(Sone)
116          * @param sone
117          *            The Sone that was unlocked
118          */
119         void fireSoneUnlocked(Sone sone) {
120                 for (CoreListener coreListener : getListeners()) {
121                         coreListener.soneUnlocked(sone);
122                 }
123         }
124
125         /**
126          * Notifies all listeners that the insert of the given Sone has started.
127          *
128          * @see SoneInsertListener#insertStarted(Sone)
129          * @param sone
130          *            The Sone being inserted
131          */
132         void fireSoneInserting(Sone sone) {
133                 for (CoreListener coreListener : getListeners()) {
134                         coreListener.soneInserting(sone);
135                 }
136         }
137
138         /**
139          * Notifies all listeners that the insert of the given Sone has finished
140          * successfully.
141          *
142          * @see SoneInsertListener#insertFinished(Sone, long)
143          * @param sone
144          *            The Sone that was inserted
145          * @param insertDuration
146          *            The insert duration (in milliseconds)
147          */
148         void fireSoneInserted(Sone sone, long insertDuration) {
149                 for (CoreListener coreListener : getListeners()) {
150                         coreListener.soneInserted(sone, insertDuration);
151                 }
152         }
153
154         /**
155          * Notifies all listeners that the insert of the given Sone was aborted.
156          *
157          * @see SoneInsertListener#insertStarted(Sone)
158          * @param sone
159          *            The Sone being inserted
160          * @param cause
161          *            The cause for the abortion (may be {@code null}
162          */
163         void fireSoneInsertAborted(Sone sone, Throwable cause) {
164                 for (CoreListener coreListener : getListeners()) {
165                         coreListener.soneInsertAborted(sone, cause);
166                 }
167         }
168
169         /**
170          * Notifies all listeners that a new version was found.
171          *
172          * @see CoreListener#updateFound(Version, long, long)
173          * @param version
174          *            The new version
175          * @param releaseTime
176          *            The release time of the new version
177          * @param latestEdition
178          *            The latest edition of the Sone homepage
179          */
180         void fireUpdateFound(Version version, long releaseTime, long latestEdition) {
181                 for (CoreListener coreListener : getListeners()) {
182                         coreListener.updateFound(version, releaseTime, latestEdition);
183                 }
184         }
185
186         /**
187          * Notifies all listeners that an image has started being inserted.
188          *
189          * @see CoreListener#imageInsertStarted(Image)
190          * @param image
191          *            The image that is now inserted
192          */
193         void fireImageInsertStarted(Image image) {
194                 for (CoreListener coreListener : getListeners()) {
195                         coreListener.imageInsertStarted(image);
196                 }
197         }
198
199         /**
200          * Notifies all listeners that an image insert was aborted by the user.
201          *
202          * @see CoreListener#imageInsertAborted(Image)
203          * @param image
204          *            The image that is not inserted anymore
205          */
206         void fireImageInsertAborted(Image image) {
207                 for (CoreListener coreListener : getListeners()) {
208                         coreListener.imageInsertAborted(image);
209                 }
210         }
211
212         /**
213          * Notifies all listeners that an image was successfully inserted.
214          *
215          * @see CoreListener#imageInsertFinished(Image)
216          * @param image
217          *            The image that was inserted
218          */
219         void fireImageInsertFinished(Image image) {
220                 for (CoreListener coreListener : getListeners()) {
221                         coreListener.imageInsertFinished(image);
222                 }
223         }
224
225         /**
226          * Notifies all listeners that an image failed to be inserted.
227          *
228          * @see CoreListener#imageInsertFailed(Image, Throwable)
229          * @param image
230          *            The image that could not be inserted
231          * @param cause
232          *            The cause of the failure
233          */
234         void fireImageInsertFailed(Image image, Throwable cause) {
235                 for (CoreListener coreListener : getListeners()) {
236                         coreListener.imageInsertFailed(image, cause);
237                 }
238         }
239
240 }