View Javadoc

1   // %2940960156:hoplugins.teamAnalyzer%
2   package hoplugins.teamAnalyzer;
3   
4   import hoplugins.Commons;
5   import hoplugins.TeamAnalyzer;
6   
7   import hoplugins.teamAnalyzer.dao.PluginConfiguration;
8   import hoplugins.teamAnalyzer.manager.MatchManager;
9   import hoplugins.teamAnalyzer.manager.MatchPopulator;
10  import hoplugins.teamAnalyzer.manager.NameManager;
11  import hoplugins.teamAnalyzer.manager.ReportManager;
12  import hoplugins.teamAnalyzer.manager.TeamManager;
13  import hoplugins.teamAnalyzer.vo.Filter;
14  import hoplugins.teamAnalyzer.vo.Team;
15  import hoplugins.teamAnalyzer.vo.TeamLineup;
16  
17  import java.util.ArrayList;
18  
19  
20  /***
21   * This is a class where all the relevant and shared plugin info are kept
22   *
23   * @author <a href=mailto:draghetto@users.sourceforge.net>Massimiliano Amato</a>
24   */
25  public class SystemManager {
26      //~ Static fields/initializers -----------------------------------------------------------------
27  
28      /*** The Selected Team */
29      private static Team selectedTeam;
30  
31      /*** The next league opponent team */
32      private static Team leagueOpponent;
33  
34      /*** The next cup/friendly opponent team */
35      private static Team cupOpponent;
36  
37      /*** The filters */
38      private static Filter filter = new Filter();
39  
40      /*** Boolean for the updating process being ongoing */
41      private static boolean updating = false;
42  
43      /*** Reference to the plugin itself */
44      private static TeamAnalyzer plugin;
45  
46      /*** The Plugin configuration */
47      private static PluginConfiguration config;
48  
49      //~ Methods ------------------------------------------------------------------------------------
50  
51      /***
52       * Set the active team
53       *
54       * @param team
55       */
56      public static void setActiveTeam(Team team) {
57          selectedTeam = team;
58      }
59  
60      /***
61       * Get the active team ID
62       *
63       * @return
64       */
65      public static int getActiveTeamId() {
66          return selectedTeam.getTeamId();
67      }
68  
69      /***
70       * Get the active team Name
71       *
72       * @return
73       */
74      public static String getActiveTeamName() {
75          return selectedTeam.getName();
76      }
77  
78      /***
79       * Update the plugin configuration
80       *
81       * @param configuration
82       */
83      public static void setConfig(PluginConfiguration configuration) {
84          config = configuration;
85      }
86  
87      /***
88       * Returns the plugin configuration
89       *
90       * @return
91       */
92      public static PluginConfiguration getConfig() {
93          return config;
94      }
95  
96      /***
97       * Get next cup/friendly opponent team Id
98       *
99       * @return
100      */
101     public static int getCupOpponentId() {
102         return cupOpponent.getTeamId();
103     }
104 
105     /***
106      * Returns the actual filter settings
107      *
108      * @return
109      */
110     public static Filter getFilter() {
111         return filter;
112     }
113 
114     /***
115      * Get next league opponent team Id
116      *
117      * @return
118      */
119     public static int getLeagueOpponentId() {
120         return leagueOpponent.getTeamId();
121     }
122 
123     /***
124      * Returns the main Plugin class
125      *
126      * @return
127      */
128     public static TeamAnalyzer getPlugin() {
129         return plugin;
130     }
131 
132     /***
133      * Initialize the instance
134      *
135      * @param aPlugin main plugin class
136      */
137     public static void initialize(TeamAnalyzer aPlugin) {
138         config = new PluginConfiguration();
139         plugin = aPlugin;
140         leagueOpponent = TeamManager.getNextLeagueOpponent();
141         cupOpponent = TeamManager.getNextCupOpponent();
142 
143         if (leagueOpponent.getTeamId() != 0) {
144             setActiveTeam(leagueOpponent);
145         } else if (cupOpponent.getTeamId() != 0) {
146             setActiveTeam(cupOpponent);
147         } else {
148             Team team = new Team();
149 
150             team.setName(Commons.getModel().getBasics().getTeamName());
151             team.setTeamId(Commons.getModel().getBasics().getTeamId());
152             setActiveTeam(team);
153         }
154     }
155 
156     /***
157      * Refresh all the plugins data after an event
158      */
159     public static void refresh() {
160         NameManager.clean();
161         filter.setMatches(new ArrayList());
162 
163         if (getActiveTeamId() == getCupOpponentId()) {
164             filter.setLeague(false);
165             filter.setQualifier(false);
166             filter.setCup(true);
167             filter.setFriendly(true);
168         } else {
169             filter.setLeague(true);
170             filter.setQualifier(true);
171             filter.setCup(false);
172             filter.setFriendly(false);
173         }
174 
175         ReportManager.clean();
176         MatchPopulator.clean();
177         MatchManager.clean();
178         plugin.getMainPanel().reload(null, 0, 0);
179         updateUI();
180     }
181 
182     /***
183      * Refrwsh only the data without recalculating everything
184      */
185     public static void refreshData() {
186         if (!updating) {
187             leagueOpponent = TeamManager.getNextLeagueOpponent();
188             cupOpponent = TeamManager.getNextCupOpponent();
189             NameManager.clean();
190             TeamManager.clean();
191             refresh();
192         }
193     }
194 
195     /***
196      * Recalculate the report
197      */
198     public static void updateReport() {
199         updating = true;
200         ReportManager.updateReport();
201         updating = false;
202         updateUI();
203     }
204 
205     /***
206      * Update the UI
207      */
208     public static void updateUI() {
209         TeamLineup lineup = ReportManager.getLineup();
210 
211         if (lineup != null) {
212             plugin.getFilterPanel().reload();
213             plugin.getMainPanel().reload(lineup, 0, 0);
214             plugin.getRecapPanel().reload(lineup);
215             plugin.getRatingPanel().reload(lineup);
216         } else {
217             plugin.getFilterPanel().reload();
218             plugin.getMainPanel().reload(null, 0, 0);
219             plugin.getRecapPanel().reload(null);
220             plugin.getRatingPanel().reload(null);
221         }
222 
223         if (config.isLineup()) {
224             plugin.getSimButton().setVisible(true);
225         } else {
226             plugin.getSimButton().setVisible(false);
227         }
228     }
229 }