1 package nl.tudelft.goal.ut2004.visualizer.gui.action;
2
3 import java.awt.event.ActionEvent;
4 import java.awt.event.ActionListener;
5
6 import javax.swing.JComboBox;
7 import javax.swing.JSpinner;
8 import javax.swing.JTextField;
9
10 import nl.tudelft.goal.ut2004.visualizer.controller.ServerController;
11 import nl.tudelft.goal.ut2004.visualizer.gui.widgets.WaypointBox;
12
13 import cz.cuni.amis.pogamut.base3d.worldview.object.Location;
14 import cz.cuni.amis.pogamut.ut2004.communication.messages.gbcommands.AddBot;
15 import cz.cuni.amis.pogamut.ut2004.communication.worldview.map.Waypoint;
16 import cz.cuni.amis.pogamut.ut2004.server.IUT2004Server;
17
18 public class AddNativeBotAction implements ActionListener {
19
20 private final JTextField botName;
21 private final nl.tudelft.goal.ut2004.visualizer.gui.widgets.WaypointBox location;
22 private final JSpinner skill;
23 private final JComboBox team;
24
25 public AddNativeBotAction(JTextField botName, WaypointBox location,
26 JSpinner skill, JComboBox team) {
27 this.botName = botName;
28 this.location = location;
29 this.skill = skill;
30 this.team = team;
31 }
32
33 @Override
34 public void actionPerformed(ActionEvent e) {
35
36 ServerController controller = ServerController.getInstance();
37 IUT2004Server server = controller.getServer();
38 assert server != null;
39
40
41
42 Waypoint waypoint = location.getSelected();
43 Location location = null;
44 if (waypoint != null) {
45 location = waypoint.getLocation();
46 }
47
48 String botName = this.botName.getText();
49 Integer skill = (Integer) this.skill.getValue();
50
51 String selectedTeam = (String) team.getSelectedItem();
52
53 Integer team = null;
54 if (selectedTeam.equals("Red")) {
55 team = 0;
56 } else if (selectedTeam.equals("Blue")) {
57 team = 1;
58 }
59
60 AddBot addBot = new AddBot(botName, location, null, skill, team, null);
61 server.getAct().act(addBot);
62 }
63
64 }