View Javadoc

1   // %3467106003:hoplugins.teamAnalyzer.ui%
2   package hoplugins.teamAnalyzer.ui;
3   
4   import hoplugins.Commons;
5   
6   import hoplugins.commons.utils.PluginProperty;
7   
8   import hoplugins.teamAnalyzer.SystemManager;
9   import hoplugins.teamAnalyzer.ht.HattrickManager;
10  import hoplugins.teamAnalyzer.manager.TeamManager;
11  import hoplugins.teamAnalyzer.ui.component.JokePanel;
12  import hoplugins.teamAnalyzer.vo.Team;
13  
14  import java.awt.BorderLayout;
15  import java.awt.CardLayout;
16  import java.awt.event.ActionEvent;
17  import java.awt.event.ActionListener;
18  import java.awt.event.ItemEvent;
19  import java.awt.event.ItemListener;
20  
21  import java.util.Iterator;
22  
23  import javax.swing.ButtonGroup;
24  import javax.swing.JButton;
25  import javax.swing.JComboBox;
26  import javax.swing.JOptionPane;
27  import javax.swing.JPanel;
28  import javax.swing.JRadioButton;
29  
30  
31  /***
32   * TODO Missing Class Documentation
33   *
34   * @author TODO Author Name
35   */
36  public class FilterPanel extends JPanel implements ActionListener {
37      //~ Static fields/initializers -----------------------------------------------------------------
38  
39      /*** TODO Missing Parameter Documentation */
40      private static final String CARD_AUTOMATIC = "AUTOMATIC CARD";
41  
42      /*** TODO Missing Parameter Documentation */
43      private static final String CARD_MANUAL = "MANUAL CARD";
44      private static boolean teamComboUpdating = false;
45  
46      //~ Instance fields ----------------------------------------------------------------------------
47  
48      private AutoFilterPanel autoPanel;
49      private JButton downloadButton = new JButton(PluginProperty.getString("Update"));
50      private JComboBox teamCombo = new JComboBox();
51      private JPanel cards = new JPanel(new CardLayout());
52      private JRadioButton radioAutomatic;
53      private JRadioButton radioManual;
54      private ManualFilterPanel manualPanel;
55      private boolean fullUpdate = false;
56  
57      //~ Constructors -------------------------------------------------------------------------------
58  
59      /***
60       * Creates a new FilterPanel object.
61       */
62      public FilterPanel() {
63          jbInit();
64      }
65  
66      //~ Methods ------------------------------------------------------------------------------------
67  
68      /***
69       * TODO Missing Method Documentation
70       *
71       * @return TODO Missing Return Method Documentation
72       */
73      public Team getSelectedTeam() {
74          return (Team) teamCombo.getSelectedItem();
75      }
76  
77      /***
78       * TODO Missing Method Documentation
79       *
80       * @param ae TODO Missing Method Parameter Documentation
81       */
82      public void actionPerformed(ActionEvent ae) {
83          Object compo = ae.getSource();
84          CardLayout cLayout = (CardLayout) (cards.getLayout());
85  
86          if (compo == radioAutomatic) {
87              SystemManager.getFilter().setAutomatic(true);
88              autoPanel.reload();
89              cLayout.show(cards, CARD_AUTOMATIC);
90  
91              return;
92          } else if (compo == radioManual) {
93              cLayout.show(cards, CARD_MANUAL);
94              SystemManager.getFilter().setAutomatic(false);
95              manualPanel.reload();
96  
97              return;
98          }
99      }
100 
101     /***
102      * TODO Missing Method Documentation
103      */
104     public void reload() {
105         if (TeamManager.isUpdated()) {
106             fillTeamCombo();
107         }
108 
109         boolean isNextOpponent = ((SystemManager.getActiveTeamId() == SystemManager
110                                                                       .getCupOpponentId())
111                                  || (SystemManager.getActiveTeamId() == SystemManager
112                                                                         .getLeagueOpponentId()));
113 
114         if (isNextOpponent) {
115             fullUpdate = true;
116             downloadButton.setEnabled(true);
117             downloadButton.setText(PluginProperty.getString("Update"));
118         } else {
119             fullUpdate = false;
120             downloadButton.setText(PluginProperty.getString("FilterPanel.RosterUpdate"));
121         }
122 
123         CardLayout cLayout = (CardLayout) (cards.getLayout());
124 
125         if (SystemManager.getFilter().isAutomatic()) {
126             radioAutomatic.setSelected(true);
127             cLayout.show(cards, CARD_AUTOMATIC);
128             autoPanel.reload();
129 
130             return;
131         }
132 
133         if (!SystemManager.getFilter().isAutomatic()) {
134             radioManual.setSelected(true);
135             cLayout.show(cards, CARD_MANUAL);
136             manualPanel.reload();
137 
138             return;
139         }
140     }
141 
142     /***
143      * TODO Missing Method Documentation
144      */
145     private void fillTeamCombo() {
146         teamComboUpdating = true;
147         teamCombo.removeAllItems();
148 
149         int i = 0;
150 
151         for (Iterator iter = TeamManager.getTeams().iterator(); iter.hasNext();) {
152             Team element = (Team) iter.next();
153 
154             teamCombo.addItem(element);
155 
156             if (SystemManager.getActiveTeamId() == element.getTeamId()) {
157                 teamCombo.setSelectedItem(element);
158             }
159 
160             i++;
161         }
162 
163         teamCombo.setMaximumRowCount(i);
164         teamComboUpdating = false;
165     }
166 
167     /***
168      * TODO Missing Method Documentation
169      */
170     private void jbInit() {
171         JPanel main = Commons.getModel().getGUI().createImagePanel();
172 
173         main.setLayout(new BorderLayout());
174         setLayout(new BorderLayout());
175         setOpaque(false);
176 
177         fillTeamCombo();
178         teamCombo.setRenderer(new ComboBoxRenderer());
179         teamCombo.setOpaque(false);
180         teamCombo.addItemListener(new ItemListener() {
181                 public void itemStateChanged(ItemEvent e) {
182                     if (!teamComboUpdating) {
183                         SystemManager.setActiveTeam((Team) teamCombo.getSelectedItem());
184                         SystemManager.refresh();
185                     }
186                 }
187             });
188 
189         JButton analyzeButton = new JButton(PluginProperty.getString("AutoFilterPanel.Analyze")); //$NON-NLS-1$
190 
191         analyzeButton.addActionListener(new ActionListener() {
192                 public void actionPerformed(ActionEvent e) {
193                     if ((SystemManager.getActiveTeamId() == 240416)
194                         && (Commons.getModel().getBasics().getTeamId() != 240416)) {
195                         JOptionPane.showMessageDialog(SystemManager.getPlugin().getPluginPanel(),
196                                                       new JokePanel(),
197                                                       PluginProperty.getString("Menu.About"),
198                                                       JOptionPane.PLAIN_MESSAGE);
199 
200                         return;
201                     }
202 
203                     if (radioManual.isSelected()) {
204                         manualPanel.setFilter();
205                     } else {
206                         autoPanel.setFilter();
207                     }
208 
209                     SystemManager.updateReport();
210                 }
211             });
212 
213         downloadButton.addActionListener(new ActionListener() {
214                 public void actionPerformed(ActionEvent e) {
215                     HattrickManager.downloadPlayers(SystemManager.getActiveTeamId());
216 
217                     if (fullUpdate) {
218                         HattrickManager.downloadMatches(SystemManager.getActiveTeamId());
219                     }
220 
221                     SystemManager.refresh();
222                 }
223             });
224 
225         JPanel teamPanel = Commons.getModel().getGUI().createImagePanel();
226 
227         teamPanel.setLayout(new BorderLayout());
228         teamPanel.add(downloadButton, BorderLayout.NORTH);
229         teamPanel.add(teamCombo, BorderLayout.SOUTH);
230         teamPanel.setOpaque(false);
231 
232         JPanel topPanel = Commons.getModel().getGUI().createImagePanel();
233 
234         topPanel.setLayout(new BorderLayout());
235         radioAutomatic = new JRadioButton(PluginProperty.getString("FilterPanel.Automatic")); //$NON-NLS-1$
236         radioAutomatic.setSelected(true);
237         radioAutomatic.addActionListener(this);
238         radioAutomatic.setOpaque(false);
239         radioManual = new JRadioButton(PluginProperty.getString("FilterPanel.Manual")); //$NON-NLS-1$
240         radioManual.addActionListener(this);
241         radioManual.setOpaque(false);
242 
243         ButtonGroup groupRadio = new ButtonGroup();
244         JPanel buttonPanel = Commons.getModel().getGUI().createImagePanel();
245 
246         buttonPanel.setLayout(new BorderLayout());
247         groupRadio.add(radioAutomatic);
248         groupRadio.add(radioManual);
249         buttonPanel.add(radioAutomatic, BorderLayout.WEST);
250         buttonPanel.add(radioManual, BorderLayout.EAST);
251         topPanel.add(teamPanel, BorderLayout.NORTH);
252         topPanel.add(buttonPanel, BorderLayout.SOUTH);
253 
254         main.add(topPanel, BorderLayout.NORTH);
255         add(main, BorderLayout.NORTH);
256         autoPanel = new AutoFilterPanel();
257         manualPanel = new ManualFilterPanel();
258         cards.add(autoPanel, CARD_AUTOMATIC);
259         cards.add(manualPanel, CARD_MANUAL);
260         add(cards, BorderLayout.CENTER);
261         add(analyzeButton, BorderLayout.SOUTH);
262     }
263 }