1
2 package hoplugins.teamAnalyzer.ui.controller;
3
4 import hoplugins.Commons;
5
6 import hoplugins.commons.utils.PluginProperty;
7
8 import hoplugins.teamAnalyzer.SystemManager;
9 import hoplugins.teamAnalyzer.ui.TeamLineupData;
10
11 import plugins.IMPTeamData;
12 import plugins.IMPTeamRatings;
13 import plugins.IMatchDetails;
14 import plugins.IMatchPredictionManager;
15
16 import java.awt.BorderLayout;
17 import java.awt.event.ActionEvent;
18 import java.awt.event.ActionListener;
19
20 import javax.swing.JDialog;
21 import javax.swing.JLabel;
22 import javax.swing.JOptionPane;
23 import javax.swing.JPanel;
24
25
26 /***
27 * Action listener for the simulation Button
28 *
29 * @author <a href=mailto:draghetto@users.sourceforge.net>Massimiliano Amato</a>
30 */
31 public class SimButtonListener implements ActionListener {
32
33
34 /*** The match prediction Manager */
35 IMatchPredictionManager manager = Commons.getModel().getMatchPredictionManager();
36
37 /*** The user team */
38 TeamLineupData myTeam;
39
40 /*** The opponent team */
41 TeamLineupData opponentTeam;
42
43
44
45 /***
46 * Creates a new SimButtonListener object.
47 *
48 * @param panel user team
49 * @param panel2 opponent team
50 */
51 public SimButtonListener(TeamLineupData panel, TeamLineupData panel2) {
52 myTeam = panel;
53 opponentTeam = panel2;
54 }
55
56
57
58 /***
59 * Action performed event listener PRepares the date for the 2 teams and lauch the
60 * MatchRatingPredictor
61 *
62 * @param e the event
63 */
64 public void actionPerformed(ActionEvent e) {
65 if ((myTeam.getMidfield() < 1) || (opponentTeam.getMidfield() < 1)) {
66 JPanel pan = new JPanel();
67
68 pan.add(new JLabel(PluginProperty.getString("Error.SetFormation")));
69 JOptionPane.showMessageDialog(SystemManager.getPlugin().getPluginPanel(), pan,
70 PluginProperty.getString("Error"),
71 JOptionPane.PLAIN_MESSAGE);
72
73 return;
74 }
75
76 IMPTeamRatings myTeamRatings = manager.generateTeamRatings(myTeam.getMidfield(),
77 myTeam.getLeftDefence(),
78 myTeam.getMiddleDefence(),
79 myTeam.getRightDefence(),
80 myTeam.getLeftAttack(),
81 myTeam.getMiddleAttack(),
82 myTeam.getRightAttack());
83
84 IMPTeamData myTeamValues = manager.generateTeamData(myTeam.getTeamPanel().getText(),
85 myTeamRatings,
86 Commons.getModel().getLineUP()
87 .getTacticType(),
88 getTacticLevel());
89
90 IMPTeamRatings opponentTeamRatings = manager.generateTeamRatings(opponentTeam.getMidfield(),
91 opponentTeam
92 .getLeftDefence(),
93 opponentTeam
94 .getMiddleDefence(),
95 opponentTeam
96 .getRightDefence(),
97 opponentTeam.getLeftAttack(),
98 opponentTeam
99 .getMiddleAttack(),
100 opponentTeam
101 .getRightAttack());
102
103 IMPTeamData opponentTeamValues = manager.generateTeamData(opponentTeam.getTeamPanel()
104 .getText(),
105 opponentTeamRatings,
106 IMatchDetails.TAKTIK_NORMAL, 0);
107
108 JPanel matchPredictionPanel;
109 String match = "";
110
111 if (Commons.getModel().getLineUP().getHeimspiel() == 1) {
112 matchPredictionPanel = Commons.getModel().getGUI().createMatchPredictionPanel(myTeamValues,
113 opponentTeamValues);
114 match = myTeamValues.getTeamName() + " - " + opponentTeamValues.getTeamName();
115 } else {
116 matchPredictionPanel = Commons.getModel().getGUI().createMatchPredictionPanel(opponentTeamValues,
117 myTeamValues);
118 match = opponentTeamValues.getTeamName() + " - " + myTeamValues.getTeamName();
119 }
120
121 JDialog d = new JDialog(Commons.getModel().getGUI().getOwner4Dialog());
122
123 d.getContentPane().setLayout(new BorderLayout());
124 d.getContentPane().add(matchPredictionPanel, BorderLayout.CENTER);
125 d.setResizable(true);
126 d.setSize(900, 600);
127 d.setTitle(match);
128 d.setVisible(true);
129 }
130
131 /***
132 * Returns the tactic level for the user team defined formation in HO Lineup
133 *
134 * @return the actual tactic level as shown in HO LIneup tab
135 */
136 private int getTacticLevel() {
137 double tacticLevel = 0d;
138
139 switch (Commons.getModel().getLineUP().getTacticType()) {
140 case IMatchDetails.TAKTIK_KONTER:
141 tacticLevel = Commons.getModel().getLineUP().getKonterSTK();
142 break;
143
144 case IMatchDetails.TAKTIK_MIDDLE:
145 tacticLevel = Commons.getModel().getLineUP().getAttackSTK();
146 break;
147
148 case IMatchDetails.TAKTIK_PRESSING:
149 tacticLevel = Commons.getModel().getLineUP().getPressingSTK();
150 break;
151
152 case IMatchDetails.TAKTIK_WINGS:
153 tacticLevel = Commons.getModel().getLineUP().getAttackSTK();
154 break;
155 }
156
157 int lvl = (int) (tacticLevel + 0.5) - 1;
158
159 return lvl;
160 }
161 }