031fdb3a77ae8e723c4126b256905dcdc9c7c4db
[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.Sone;
22 import net.pterodactylus.util.event.AbstractListenerManager;
23 import net.pterodactylus.util.version.Version;
24
25 /**
26  * Manager for {@link CoreListener}s.
27  *
28  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
29  */
30 public class CoreListenerManager extends AbstractListenerManager<Core, CoreListener> {
31
32         /**
33          * Creates a new core listener manager.
34          *
35          * @param source
36          *            The Core
37          */
38         public CoreListenerManager(Core source) {
39                 super(source);
40         }
41
42         //
43         // ACTIONS
44         //
45
46         /**
47          * Notifies all listeners that the given Sone was locked.
48          *
49          * @see CoreListener#soneLocked(Sone)
50          * @param sone
51          *            The Sone that was locked
52          */
53         void fireSoneLocked(Sone sone) {
54                 for (CoreListener coreListener : getListeners()) {
55                         coreListener.soneLocked(sone);
56                 }
57         }
58
59         /**
60          * Notifies all listeners that the given Sone was unlocked.
61          *
62          * @see CoreListener#soneUnlocked(Sone)
63          * @param sone
64          *            The Sone that was unlocked
65          */
66         void fireSoneUnlocked(Sone sone) {
67                 for (CoreListener coreListener : getListeners()) {
68                         coreListener.soneUnlocked(sone);
69                 }
70         }
71
72         /**
73          * Notifies all listeners that the insert of the given Sone has started.
74          *
75          * @see SoneInsertListener#insertStarted(Sone)
76          * @param sone
77          *            The Sone being inserted
78          */
79         void fireSoneInserting(Sone sone) {
80                 for (CoreListener coreListener : getListeners()) {
81                         coreListener.soneInserting(sone);
82                 }
83         }
84
85         /**
86          * Notifies all listeners that the insert of the given Sone has finished
87          * successfully.
88          *
89          * @see SoneInsertListener#insertFinished(Sone, long)
90          * @param sone
91          *            The Sone that was inserted
92          * @param insertDuration
93          *            The insert duration (in milliseconds)
94          */
95         void fireSoneInserted(Sone sone, long insertDuration) {
96                 for (CoreListener coreListener : getListeners()) {
97                         coreListener.soneInserted(sone, insertDuration);
98                 }
99         }
100
101         /**
102          * Notifies all listeners that the insert of the given Sone was aborted.
103          *
104          * @see SoneInsertListener#insertStarted(Sone)
105          * @param sone
106          *            The Sone being inserted
107          * @param cause
108          *            The cause for the abortion (may be {@code null}
109          */
110         void fireSoneInsertAborted(Sone sone, Throwable cause) {
111                 for (CoreListener coreListener : getListeners()) {
112                         coreListener.soneInsertAborted(sone, cause);
113                 }
114         }
115
116         /**
117          * Notifies all listeners that a new version was found.
118          *
119          * @see CoreListener#updateFound(Version, long, long)
120          * @param version
121          *            The new version
122          * @param releaseTime
123          *            The release time of the new version
124          * @param latestEdition
125          *            The latest edition of the Sone homepage
126          */
127         void fireUpdateFound(Version version, long releaseTime, long latestEdition) {
128                 for (CoreListener coreListener : getListeners()) {
129                         coreListener.updateFound(version, releaseTime, latestEdition);
130                 }
131         }
132
133         /**
134          * Notifies all listeners that an image has started being inserted.
135          *
136          * @see CoreListener#imageInsertStarted(Image)
137          * @param image
138          *            The image that is now inserted
139          */
140         void fireImageInsertStarted(Image image) {
141                 for (CoreListener coreListener : getListeners()) {
142                         coreListener.imageInsertStarted(image);
143                 }
144         }
145
146         /**
147          * Notifies all listeners that an image insert was aborted by the user.
148          *
149          * @see CoreListener#imageInsertAborted(Image)
150          * @param image
151          *            The image that is not inserted anymore
152          */
153         void fireImageInsertAborted(Image image) {
154                 for (CoreListener coreListener : getListeners()) {
155                         coreListener.imageInsertAborted(image);
156                 }
157         }
158
159         /**
160          * Notifies all listeners that an image was successfully inserted.
161          *
162          * @see CoreListener#imageInsertFinished(Image)
163          * @param image
164          *            The image that was inserted
165          */
166         void fireImageInsertFinished(Image image) {
167                 for (CoreListener coreListener : getListeners()) {
168                         coreListener.imageInsertFinished(image);
169                 }
170         }
171
172         /**
173          * Notifies all listeners that an image failed to be inserted.
174          *
175          * @see CoreListener#imageInsertFailed(Image, Throwable)
176          * @param image
177          *            The image that could not be inserted
178          * @param cause
179          *            The cause of the failure
180          */
181         void fireImageInsertFailed(Image image, Throwable cause) {
182                 for (CoreListener coreListener : getListeners()) {
183                         coreListener.imageInsertFailed(image, cause);
184                 }
185         }
186
187 }