1 | package dk.deepthought.sidious.gui; |
2 | |
3 | import java.util.ArrayList; |
4 | import java.util.List; |
5 | |
6 | import dk.deepthought.sidious.planner.AStarAlgorithm; |
7 | import dk.deepthought.sidious.planner.Plan; |
8 | import dk.deepthought.sidious.planner.graph.Vertex; |
9 | |
10 | /** |
11 | * Class works as a provider of messages from within the planner. |
12 | * |
13 | * @author Deepthought |
14 | * |
15 | */ |
16 | public class SidiousOutput { |
17 | |
18 | /** |
19 | * The singleton instance of this. |
20 | */ |
21 | private static final SidiousOutput INSTANCE = new SidiousOutput(); |
22 | |
23 | /** |
24 | * List of listeners. |
25 | */ |
26 | private static List<SidiousController> listeners = new ArrayList<SidiousController>(); |
27 | |
28 | /** |
29 | * Private constructor. |
30 | */ |
31 | private SidiousOutput() { |
32 | } |
33 | |
34 | /** |
35 | * Gets the singleton instance of this. |
36 | * |
37 | * @return the singleton instance. |
38 | */ |
39 | public static SidiousOutput getInstance() { |
40 | return INSTANCE; |
41 | } |
42 | |
43 | /** |
44 | * Adds a vertex to this. |
45 | * <p> |
46 | * Is called from the jAStar method in the AStarAlgorithm class. |
47 | * |
48 | * @see AStarAlgorithm |
49 | * @param vertex |
50 | */ |
51 | public void addVertex(Vertex vertex) { |
52 | for (SidiousController controller : listeners) { |
53 | controller.vertex(vertex); |
54 | } |
55 | } |
56 | |
57 | /** |
58 | * Registers the specified controller as listener of this. |
59 | * |
60 | * @param controller |
61 | * the controller to register |
62 | * |
63 | */ |
64 | public void register(SidiousController controller) { |
65 | listeners.add(controller); |
66 | } |
67 | |
68 | /** |
69 | * Adds a finished plan to this. All listeners are notified. |
70 | * |
71 | * @param plan |
72 | * the plan to add |
73 | */ |
74 | public void addFinishedPlan(Plan plan) { |
75 | for (SidiousController controller : listeners) { |
76 | controller.finished(plan); |
77 | } |
78 | } |
79 | |
80 | } |