1
2 package hoplugins;
3
4 import hoplugins.commons.ui.DebugWindow;
5 import hoplugins.commons.utils.PluginProperty;
6
7 import hoplugins.teamAnalyzer.SystemManager;
8 import hoplugins.teamAnalyzer.dao.DividerDAO;
9 import hoplugins.teamAnalyzer.ui.FilterPanel;
10 import hoplugins.teamAnalyzer.ui.MainPanel;
11 import hoplugins.teamAnalyzer.ui.RatingPanel;
12 import hoplugins.teamAnalyzer.ui.RecapPanel;
13 import hoplugins.teamAnalyzer.ui.component.FavouriteMenu;
14 import hoplugins.teamAnalyzer.ui.component.SettingPanel;
15 import hoplugins.teamAnalyzer.ui.controller.AboutItemListener;
16 import hoplugins.teamAnalyzer.ui.controller.DividerListener;
17 import hoplugins.teamAnalyzer.ui.controller.DownloadItemListener;
18 import hoplugins.teamAnalyzer.ui.controller.HelpItemListener;
19 import hoplugins.teamAnalyzer.ui.controller.ImportItemListener;
20 import hoplugins.teamAnalyzer.ui.controller.SimButtonListener;
21
22 import plugins.IHOMiniModel;
23 import plugins.IOfficialPlugin;
24 import plugins.IPlugin;
25 import plugins.IRefreshable;
26
27 import java.awt.BorderLayout;
28
29 import java.io.File;
30
31 import javax.swing.JButton;
32 import javax.swing.JMenu;
33 import javax.swing.JMenuItem;
34 import javax.swing.JPanel;
35 import javax.swing.JSeparator;
36 import javax.swing.JSplitPane;
37
38
39 /***
40 * TeamAnalyzer Plugin main Class
41 *
42 * @author <a href=mailto:draghetto@users.sourceforge.net>Massimiliano Amato</a>
43 */
44 public class TeamAnalyzer implements IPlugin, IRefreshable, IOfficialPlugin {
45
46
47 /*** PLugin String name */
48 private final String PLUGIN_NAME = "TeamAnalyzer";
49
50 /*** Plugin version constant */
51 private final double PLUGIN_VERSION = 2.6;
52
53 /*** Plugin Id */
54 private final int PLUGIN_ID = 14;
55
56 /*** Favourite Team Menu Reference */
57 private FavouriteMenu submenu;
58 private FilterPanel filterPanel;
59 private JButton simButton = new JButton();
60 private JPanel pluginPanel;
61 private MainPanel mainPanel;
62 private RatingPanel ratingPanel;
63 private RecapPanel recapPanel;
64
65
66
67 /***
68 * Returns the Filter Panel
69 *
70 * @return
71 */
72 public FilterPanel getFilterPanel() {
73 return filterPanel;
74 }
75
76 /***
77 * Returns the Team panel
78 *
79 * @return
80 */
81 public MainPanel getMainPanel() {
82 return mainPanel;
83 }
84
85
86
87
88 public String getName() {
89 return getPluginName() + " " + getVersion();
90 }
91
92 /***
93 * Returns the pluginId
94 *
95 * @return
96 */
97 public int getPluginID() {
98 return PLUGIN_ID;
99 }
100
101
102
103
104 public String getPluginName() {
105 return PLUGIN_NAME;
106 }
107
108 /***
109 * Returns the main plugin panel
110 *
111 * @return
112 */
113 public JPanel getPluginPanel() {
114 return pluginPanel;
115 }
116
117 /***
118 * Returns the rating panel
119 *
120 * @return
121 */
122 public RatingPanel getRatingPanel() {
123 return ratingPanel;
124 }
125
126 /***
127 * Returns the recap panel
128 *
129 * @return
130 */
131 public RecapPanel getRecapPanel() {
132 return recapPanel;
133 }
134
135 /***
136 * Returns the Simulate Button reference
137 *
138 * @return
139 */
140 public JButton getSimButton() {
141 return simButton;
142 }
143
144
145
146
147 public File[] getUnquenchableFiles() {
148 return null;
149 }
150
151 /***
152 * Returns the plugin version
153 *
154 * @return
155 */
156 public double getVersion() {
157 return PLUGIN_VERSION;
158 }
159
160 /***
161 * MEthod that refresh the data after an event
162 */
163 public void refresh() {
164 try {
165 SystemManager.refreshData();
166 } catch (RuntimeException e) {
167 e.printStackTrace();
168 }
169 }
170
171
172
173
174 public void start(IHOMiniModel arg0) {
175 try {
176 SystemManager.initialize(this);
177 jbInit();
178 simButton.addActionListener(new SimButtonListener(mainPanel.getMyTeamLineupPanel(),
179 mainPanel.getOpponentTeamLineupPanel()));
180 SystemManager.refreshData();
181 } catch (RuntimeException e) {
182 DebugWindow.debug(e);
183 }
184 }
185
186 /***
187 * Initialize the GUI
188 */
189 private void jbInit() {
190 filterPanel = new FilterPanel();
191 recapPanel = new RecapPanel();
192 mainPanel = new MainPanel();
193 pluginPanel = new JPanel();
194 ratingPanel = new RatingPanel();
195 pluginPanel.setLayout(new BorderLayout());
196
197 JPanel buttonPanel = Commons.getModel().getGUI().createImagePanel();
198
199 buttonPanel.setLayout(new BorderLayout());
200 simButton.setText(PluginProperty.getString("Simulate"));
201 buttonPanel.add(simButton, BorderLayout.CENTER);
202
203 JSplitPane panel = new JSplitPane(0, ratingPanel, buttonPanel);
204
205 panel.setDividerSize(1);
206 panel.setResizeWeight(1);
207 panel.setDividerLocation(DividerDAO.getDividerPosition("LowerLeftDivider"));
208 panel.addPropertyChangeListener(JSplitPane.DIVIDER_LOCATION_PROPERTY,
209 new DividerListener("LowerLeftDivider"));
210
211
212 JSplitPane leftPanel = new JSplitPane(0, filterPanel, panel);
213
214 leftPanel.setDividerLocation(DividerDAO.getDividerPosition("UpperLeftDivider"));
215 leftPanel.addPropertyChangeListener(JSplitPane.DIVIDER_LOCATION_PROPERTY,
216 new DividerListener("UpperLeftDivider"));
217
218 JSplitPane mainPanel2 = new JSplitPane(1, leftPanel, mainPanel);
219
220 mainPanel2.setDividerLocation(DividerDAO.getDividerPosition("MainDivider"));
221 mainPanel2.addPropertyChangeListener(JSplitPane.DIVIDER_LOCATION_PROPERTY,
222 new DividerListener("MainDivider"));
223
224 JSplitPane m_splitPane = new JSplitPane(0, mainPanel2, recapPanel);
225
226 m_splitPane.setDividerLocation(DividerDAO.getDividerPosition("BottomDivider"));
227 m_splitPane.addPropertyChangeListener(JSplitPane.DIVIDER_LOCATION_PROPERTY,
228 new DividerListener("BottomDivider"));
229 pluginPanel.add(m_splitPane, BorderLayout.CENTER);
230
231 JMenu menu = new JMenu(getPluginName());
232 JMenuItem item2 = new javax.swing.JMenuItem(PluginProperty.getString("Menu.About"));
233 JMenuItem item3 = new javax.swing.JMenuItem(PluginProperty.getString("Menu.DownloadMatch"));
234 JMenuItem item4 = new javax.swing.JMenuItem(PluginProperty.getString("Help"));
235 JMenuItem item5 = new javax.swing.JMenuItem("Import All Teams");
236
237 item2.addActionListener(new AboutItemListener());
238 item3.addActionListener(new DownloadItemListener());
239 item4.addActionListener(new HelpItemListener());
240 item5.addActionListener(new ImportItemListener());
241
242
243 menu.add(item3);
244 menu.add(new JSeparator());
245 menu.add(item4);
246 menu.add(item2);
247
248 if (Commons.getModel().getHelper().isDevVersion()) {
249 menu.add(item5);
250 }
251
252 menu.add(new JSeparator());
253 submenu = new FavouriteMenu();
254 menu.add(submenu);
255
256 Commons.getModel().getGUI().addOptionPanel(getPluginName(), new SettingPanel());
257 Commons.getModel().getGUI().addMenu(menu);
258
259 Commons.getModel().getGUI().addTab(getPluginName(), pluginPanel);
260 Commons.getModel().getGUI().registerRefreshable(this);
261 }
262 }