View Javadoc

1   // %1193228360:hoplugins.teamAnalyzer.ui.component%
2   package hoplugins.teamAnalyzer.ui.component;
3   
4   import hoplugins.Commons;
5   
6   import hoplugins.commons.utils.PluginProperty;
7   
8   import hoplugins.teamAnalyzer.SystemManager;
9   
10  import java.awt.BorderLayout;
11  import java.awt.GridLayout;
12  import java.awt.event.ActionEvent;
13  
14  import javax.swing.JCheckBox;
15  import javax.swing.JComponent;
16  import javax.swing.JLabel;
17  import javax.swing.JPanel;
18  
19  
20  /***
21   * A panel that allows the user to configure the plugin
22   *
23   * @author <a href=mailto:draghetto@users.sourceforge.net>Massimiliano Amato</a>
24   */
25  public class SettingPanel extends JPanel {
26      //~ Instance fields ----------------------------------------------------------------------------
27  
28      private JCheckBox checkName = new JCheckBox();
29      private JCheckBox descRating = new JCheckBox();
30      private JCheckBox loddarStats = new JCheckBox();
31      private JCheckBox mixedLineup = new JCheckBox();
32      private JCheckBox myLineup = new JCheckBox();
33      private JCheckBox numberRating = new JCheckBox();
34      private JCheckBox playerInfo = new JCheckBox();
35      private JCheckBox smartSquad = new JCheckBox();
36      private JCheckBox squad = new JCheckBox();
37      private JCheckBox stars = new JCheckBox();
38      private JCheckBox tacticDetail = new JCheckBox();
39      private JCheckBox totalStrength = new JCheckBox();
40      private JCheckBox unavailable = new JCheckBox();
41  
42      //~ Constructors -------------------------------------------------------------------------------
43  
44      /***
45       * Constructs a new instance.
46       */
47      public SettingPanel() {
48          super();
49          numberRating.setSelected(SystemManager.getConfig().isNumericRating());
50          numberRating.setOpaque(false);
51          descRating.setSelected(SystemManager.getConfig().isDescriptionRating());
52          descRating.setOpaque(false);
53          myLineup.setSelected(SystemManager.getConfig().isLineup());
54          myLineup.setOpaque(false);
55          tacticDetail.setSelected(SystemManager.getConfig().isTacticDetail());
56          tacticDetail.setOpaque(false);
57          unavailable.setSelected(SystemManager.getConfig().isShowUnavailable());
58          unavailable.setOpaque(false);
59          playerInfo.setSelected(SystemManager.getConfig().isShowPlayerInfo());
60          playerInfo.setOpaque(false);
61          mixedLineup.setSelected(SystemManager.getConfig().isMixedLineup());
62          mixedLineup.setOpaque(false);
63          stars.setSelected(SystemManager.getConfig().isStars());
64          stars.setOpaque(false);
65          smartSquad.setSelected(SystemManager.getConfig().isSmartSquad());
66          smartSquad.setOpaque(false);
67          loddarStats.setSelected(SystemManager.getConfig().isLoddarStats());
68          loddarStats.setOpaque(false);
69          squad.setSelected(SystemManager.getConfig().isSquad());
70          squad.setOpaque(false);
71          totalStrength.setSelected(SystemManager.getConfig().isTotalStrength());
72          totalStrength.setOpaque(false);
73          checkName.setSelected(SystemManager.getConfig().isCheckTeamName());
74          checkName.setOpaque(false);
75          jbInit();
76      }
77  
78      //~ Methods ------------------------------------------------------------------------------------
79  
80      /***
81       * Create a new Panel
82       *
83       * @param string Label text
84       * @param checkBox CheckBox
85       *
86       * @return a panel
87       */
88      private JPanel createPanel(String string, JComponent checkBox) {
89          JPanel panel = Commons.getModel().getGUI().createImagePanel();
90  
91          panel.setLayout(new BorderLayout());
92          panel.setOpaque(false);
93  
94          JPanel innerPanel = Commons.getModel().getGUI().createImagePanel();
95  
96          //innerPanel.setLayout(new BorderLayout());
97          innerPanel.add(checkBox);
98          innerPanel.add(new JLabel(string, JLabel.LEFT));
99          innerPanel.setOpaque(false);
100         panel.add(innerPanel, BorderLayout.WEST);
101 
102         return panel;
103     }
104 
105     /***
106      * Initialize listeners
107      */
108     private void initListeners() {
109         numberRating.addActionListener(new java.awt.event.ActionListener() {
110                 public void actionPerformed(ActionEvent e) {
111                     if (numberRating.isSelected() || descRating.isSelected()) {
112                         SystemManager.getConfig().setNumericRating(numberRating.isSelected());
113                         SystemManager.updateUI();
114                     } else {
115                         numberRating.setSelected(true);
116                     }
117                 }
118             });
119 
120         descRating.addActionListener(new java.awt.event.ActionListener() {
121                 public void actionPerformed(ActionEvent e) {
122                     if (numberRating.isSelected() || descRating.isSelected()) {
123                         SystemManager.getConfig().setDescriptionRating(descRating.isSelected());
124                         SystemManager.updateUI();
125                     } else {
126                         descRating.setSelected(true);
127                     }
128                 }
129             });
130 
131         stars.addActionListener(new java.awt.event.ActionListener() {
132                 public void actionPerformed(ActionEvent e) {
133                     SystemManager.getConfig().setStars(stars.isSelected());
134                     SystemManager.updateUI();
135                     SystemManager.updateUI();
136                 }
137             });
138         totalStrength.addActionListener(new java.awt.event.ActionListener() {
139                 public void actionPerformed(ActionEvent e) {
140                     SystemManager.getConfig().setTotalStrength(totalStrength.isSelected());
141                     SystemManager.updateUI();
142                     SystemManager.updateUI();
143                 }
144             });
145         checkName.addActionListener(new java.awt.event.ActionListener() {
146                 public void actionPerformed(ActionEvent e) {
147                     SystemManager.getConfig().setCheckTeamName(checkName.isSelected());
148                     SystemManager.updateUI();
149                     SystemManager.updateUI();
150                 }
151             });
152 
153         squad.addActionListener(new java.awt.event.ActionListener() {
154                 public void actionPerformed(ActionEvent e) {
155                     SystemManager.getConfig().setSquad(squad.isSelected());
156                     SystemManager.updateUI();
157                     SystemManager.updateUI();
158                 }
159             });
160         smartSquad.addActionListener(new java.awt.event.ActionListener() {
161                 public void actionPerformed(ActionEvent e) {
162                     SystemManager.getConfig().setSmartSquad(smartSquad.isSelected());
163                     SystemManager.updateUI();
164                     SystemManager.updateUI();
165                 }
166             });
167 
168         loddarStats.addActionListener(new java.awt.event.ActionListener() {
169                 public void actionPerformed(ActionEvent e) {
170                     SystemManager.getConfig().setLoddarStats(loddarStats.isSelected());
171                     SystemManager.updateUI();
172                     SystemManager.updateUI();
173                 }
174             });
175 
176         myLineup.addActionListener(new java.awt.event.ActionListener() {
177                 public void actionPerformed(ActionEvent e) {
178                     SystemManager.getConfig().setLineup(myLineup.isSelected());
179                     SystemManager.updateUI();
180                 }
181             });
182 
183         tacticDetail.addActionListener(new java.awt.event.ActionListener() {
184                 public void actionPerformed(ActionEvent e) {
185                     SystemManager.getConfig().setTacticDetail(tacticDetail.isSelected());
186                     SystemManager.updateUI();
187                 }
188             });
189 
190         unavailable.addActionListener(new java.awt.event.ActionListener() {
191                 public void actionPerformed(ActionEvent e) {
192                     SystemManager.getConfig().setShowUnavailable(unavailable.isSelected());
193                     SystemManager.updateUI();
194                 }
195             });
196         playerInfo.addActionListener(new java.awt.event.ActionListener() {
197                 public void actionPerformed(ActionEvent e) {
198                     SystemManager.getConfig().setShowPlayerInfo(playerInfo.isSelected());
199                     SystemManager.updateUI();
200                 }
201             });
202         mixedLineup.addActionListener(new java.awt.event.ActionListener() {
203                 public void actionPerformed(ActionEvent e) {
204                     SystemManager.getConfig().setMixedLineup(mixedLineup.isSelected());
205                     SystemManager.updateUI();
206                 }
207             });
208     }
209 
210     /***
211      * Initializes the state of this instance.
212      */
213     private void jbInit() {
214         initListeners();
215 
216         JPanel mainPanel = Commons.getModel().getGUI().createImagePanel();
217 
218         mainPanel.setLayout(new GridLayout(12, 1));
219         mainPanel.setOpaque(false);
220         mainPanel.add(createPanel(PluginProperty.getString("SettingPanel.MyLineup"), myLineup));
221         mainPanel.add(createPanel(PluginProperty.getString("SettingPanel.TacticDetail"),
222                                   tacticDetail));
223         mainPanel.add(createPanel(PluginProperty.getString("SettingPanel.MixedLineup"), mixedLineup));
224         mainPanel.add(createPanel(PluginProperty.getString("SettingPanel.NumericRatings"),
225                                   numberRating));
226         mainPanel.add(createPanel(PluginProperty.getString("SettingPanel.DescriptionRatings"),
227                                   descRating));
228 
229         //mainPanel.add(createPanel(PluginProperty.getString("SettingPanel.ShowUnavailable"), unavailable));
230         mainPanel.add(createPanel(PluginProperty.getString("RecapPanel.Stars"), stars));
231         mainPanel.add(createPanel(Commons.getModel().getResource().getProperty("Gesamtstaerke"),
232                                   totalStrength));
233         mainPanel.add(createPanel(PluginProperty.getString("Squad"), squad));
234         mainPanel.add(createPanel(PluginProperty.getString("SmartSquad"), smartSquad));
235         mainPanel.add(createPanel("LoddarStats", loddarStats));
236         mainPanel.add(createPanel("Player Info", playerInfo));
237         mainPanel.add(createPanel(PluginProperty.getString("SettingPanel.CheckName"), checkName));
238 
239         setLayout(new BorderLayout());
240         setOpaque(false);
241         add(mainPanel, BorderLayout.CENTER);
242     }
243 }