a4c3b78e3637b27029bf29bceca0544883e4ab62
[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 insert of the given Sone was aborted.
48          *
49          * @see SoneInsertListener#insertStarted(Sone)
50          * @param sone
51          *            The Sone being inserted
52          * @param cause
53          *            The cause for the abortion (may be {@code null}
54          */
55         void fireSoneInsertAborted(Sone sone, Throwable cause) {
56                 for (CoreListener coreListener : getListeners()) {
57                         coreListener.soneInsertAborted(sone, cause);
58                 }
59         }
60
61         /**
62          * Notifies all listeners that a new version was found.
63          *
64          * @see CoreListener#updateFound(Version, long, long)
65          * @param version
66          *            The new version
67          * @param releaseTime
68          *            The release time of the new version
69          * @param latestEdition
70          *            The latest edition of the Sone homepage
71          */
72         void fireUpdateFound(Version version, long releaseTime, long latestEdition) {
73                 for (CoreListener coreListener : getListeners()) {
74                         coreListener.updateFound(version, releaseTime, latestEdition);
75                 }
76         }
77
78         /**
79          * Notifies all listeners that an image has started being inserted.
80          *
81          * @see CoreListener#imageInsertStarted(Image)
82          * @param image
83          *            The image that is now inserted
84          */
85         void fireImageInsertStarted(Image image) {
86                 for (CoreListener coreListener : getListeners()) {
87                         coreListener.imageInsertStarted(image);
88                 }
89         }
90
91         /**
92          * Notifies all listeners that an image insert was aborted by the user.
93          *
94          * @see CoreListener#imageInsertAborted(Image)
95          * @param image
96          *            The image that is not inserted anymore
97          */
98         void fireImageInsertAborted(Image image) {
99                 for (CoreListener coreListener : getListeners()) {
100                         coreListener.imageInsertAborted(image);
101                 }
102         }
103
104         /**
105          * Notifies all listeners that an image was successfully inserted.
106          *
107          * @see CoreListener#imageInsertFinished(Image)
108          * @param image
109          *            The image that was inserted
110          */
111         void fireImageInsertFinished(Image image) {
112                 for (CoreListener coreListener : getListeners()) {
113                         coreListener.imageInsertFinished(image);
114                 }
115         }
116
117         /**
118          * Notifies all listeners that an image failed to be inserted.
119          *
120          * @see CoreListener#imageInsertFailed(Image, Throwable)
121          * @param image
122          *            The image that could not be inserted
123          * @param cause
124          *            The cause of the failure
125          */
126         void fireImageInsertFailed(Image image, Throwable cause) {
127                 for (CoreListener coreListener : getListeners()) {
128                         coreListener.imageInsertFailed(image, cause);
129                 }
130         }
131
132 }