View Javadoc

1   // %1818257735:hoplugins%
2   package hoplugins;
3   
4   import hoplugins.commons.ui.DebugWindow;
5   
6   import hoplugins.trainingExperience.OldTrainingManager;
7   import hoplugins.trainingExperience.dao.DividerDAO;
8   import hoplugins.trainingExperience.ui.MainPanel;
9   import hoplugins.trainingExperience.ui.PlayerDetailPanel;
10  import hoplugins.trainingExperience.ui.SkillupPanel;
11  import hoplugins.trainingExperience.ui.StaffPanel;
12  import hoplugins.trainingExperience.ui.TrainingPanel;
13  import hoplugins.trainingExperience.ui.component.DividerListener;
14  
15  import plugins.IHOMiniModel;
16  import plugins.IOfficialPlugin;
17  import plugins.IPlugin;
18  import plugins.IRefreshable;
19  import plugins.ISpieler;
20  
21  import java.awt.BorderLayout;
22  
23  import java.io.File;
24  
25  import javax.swing.JPanel;
26  import javax.swing.JSplitPane;
27  
28  
29  /***
30   * Main class for Training Plugin
31   */
32  public class TrainingExperience implements IPlugin, IRefreshable, IOfficialPlugin {
33      //~ Static fields/initializers -----------------------------------------------------------------
34  
35      /*** The currently selected player */
36      private static ISpieler activePlayer;
37  
38      /*** Class that keep track of the past skillup */
39      private static OldTrainingManager manager;
40  
41      /*** Main table panel */
42      private static MainPanel tabbedPanel;
43  
44      /*** Prevision table */
45      private static PlayerDetailPanel playerDetailPanel;
46  
47      /*** Table of past skillups */
48      private static SkillupPanel skillupPanel;
49  
50      /*** Table of old past and future trainings */
51      private static TrainingPanel trainPanel;
52  
53      /*** Staff panel */
54      private static StaffPanel staffPanel;
55  
56      /*** Plugin Panel */
57      private static JPanel pluginPanel;
58  
59      //~ Methods ------------------------------------------------------------------------------------
60  
61      /***
62       * Returns the Plugin name
63       *
64       * @return plugin name
65       */
66      public String getPluginName() {
67          return "Training Experience"; //$NON-NLS-1$
68      }
69  
70      /***
71       * Returns the main Plugin Panel
72       *
73       * @return
74       */
75      public static JPanel getPluginPanel() {
76          return pluginPanel;
77      }
78  
79      /***
80       * Returns the SkillupManager
81       *
82       * @return
83       */
84      public static OldTrainingManager getSkillupManager() {
85          return manager;
86      }
87  
88      /***
89       * Returns the Skillup Panel where the past skillup are shown
90       *
91       * @return
92       */
93      public static SkillupPanel getSkillupPanel() {
94          return skillupPanel;
95      }
96  
97      /***
98       * Returns the Staff Panel where the staff settings are shown
99       *
100      * @return
101      */
102     public static StaffPanel getStaffPanel() {
103         return staffPanel;
104     }
105 
106     /***
107      * Returns the Training Panel where the past and future training are shown
108      *
109      * @return
110      */
111     public static TrainingPanel getTrainPanel() {
112         return trainPanel;
113     }
114 
115     /***
116      * DOCUMENT ME!
117      *
118      * @return null
119      */
120     public File[] getUnquenchableFiles() {
121         return null;
122     }
123 
124     /***
125      * When called by HO reload everything!
126      */
127     public void refresh() {
128         // reset the selected player
129         activePlayer = null;
130 
131         // reload the trainingPanel
132         trainPanel.reload();
133 
134         // reload the staff, could have changed
135         staffPanel.reload();
136 
137         // recalculate and update the main panel		
138         tabbedPanel.reload();
139 
140         // and finally recalculate the player previsions
141         refreshPlayerDetail();
142     }
143 
144     /***
145      * Refresh all the previsions, this is used when we don't have downloaded anything from HT  but
146      * the user has changed something in the staff or in the future trainings
147      */
148     public static void refreshPlayerDetail() {
149         // reload the past skillups		
150         skillupPanel.reload(activePlayer);
151 
152         // recalculate and show the previsions
153         playerDetailPanel.reload(activePlayer);
154 
155         //update upper table!
156         tabbedPanel.getOutput().reload();
157         tabbedPanel.getRecap().reload();
158     }
159 
160     /***
161      * Sets the new active player and recalculate everything
162      *
163      * @param player the new selected player
164      */
165     public static void selectPlayer(ISpieler player) {
166         activePlayer = player;
167 
168         // regenerate the past skillup using the manager
169         manager = new OldTrainingManager(player);
170 
171         // reload the past skillups		
172         skillupPanel.reload(activePlayer);
173 
174         // recalculate and show the previsions
175         playerDetailPanel.reload(activePlayer);
176     }
177 
178     /***
179      * Returns the plugin full name, with version
180      *
181      * @return plugin fullname
182      */
183     public String getName() {
184         return getPluginName() + " " + getVersion(); //$NON-NLS-1$
185     }
186 
187     /***
188      * Returns the plugin id
189      *
190      * @return plugin id
191      */
192     public int getPluginID() {
193         return 23;
194     }
195 
196     /***
197      * Return the main tab panel
198      *
199      * @return MainPanel
200      */
201     public static MainPanel getTabbedPanel() {
202         return tabbedPanel;
203     }
204 
205     /***
206      * Returns the plugin version
207      *
208      * @return the plugin version
209      */
210     public double getVersion() {
211         return 1.1;
212     }
213 
214     /*
215      * (non-Javadoc)
216      * @see plugins.IPlugin#start(plugins.IHOMiniModel)
217      * Instantiate the panels and organize them in the gui!
218      */
219     public void start(IHOMiniModel hOMiniModel) {
220         try {
221             pluginPanel = Commons.getModel().getGUI().createImagePanel();
222             pluginPanel.setLayout(new BorderLayout());
223             skillupPanel = new SkillupPanel();
224             playerDetailPanel = new PlayerDetailPanel();
225             trainPanel = new TrainingPanel();
226             staffPanel = new StaffPanel();
227             tabbedPanel = new MainPanel();
228 
229             JSplitPane leftPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, skillupPanel, staffPanel);
230 
231             leftPane.setResizeWeight(1);
232             leftPane.setDividerLocation(DividerDAO.getDividerPosition("LowerLeftDivider")); //$NON-NLS-1$
233             leftPane.addPropertyChangeListener(JSplitPane.DIVIDER_LOCATION_PROPERTY,
234                                                new DividerListener("LowerLeftDivider")); //$NON-NLS-1$
235 
236             JSplitPane bottomPanel = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftPane,
237                                                     playerDetailPanel);
238 
239             bottomPanel.setDividerLocation(DividerDAO.getDividerPosition("BottomDivider")); //$NON-NLS-1$
240             bottomPanel.addPropertyChangeListener(JSplitPane.DIVIDER_LOCATION_PROPERTY,
241                                                   new DividerListener("BottomDivider")); //$NON-NLS-1$
242 
243             JSplitPane splitPanel = new JSplitPane(JSplitPane.VERTICAL_SPLIT, tabbedPanel,
244                                                    bottomPanel);
245 
246             splitPanel.setDividerLocation(DividerDAO.getDividerPosition("MainDivider")); //$NON-NLS-1$
247             splitPanel.addPropertyChangeListener(JSplitPane.DIVIDER_LOCATION_PROPERTY,
248                                                  new DividerListener("MainDivider")); //$NON-NLS-1$
249 
250             JSplitPane mainPanel = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, splitPanel,
251                                                   trainPanel);
252 
253             mainPanel.setDividerLocation(DividerDAO.getDividerPosition("RightDivider")); //$NON-NLS-1$
254             mainPanel.addPropertyChangeListener(JSplitPane.DIVIDER_LOCATION_PROPERTY,
255                                                 new DividerListener("RightDivider")); //$NON-NLS-1$
256 
257             mainPanel.setOpaque(false);
258             pluginPanel.add(mainPanel, BorderLayout.CENTER);
259             Commons.getModel().getGUI().addTab(getPluginName(), pluginPanel);
260             Commons.getModel().getGUI().registerRefreshable(this);
261         } catch (RuntimeException e) {
262             e.printStackTrace();
263             DebugWindow.debug(e);
264         }
265     }
266 }