1 package nl.tudelft.goal.ut2004.visualizer.gui.action;
2
3 import java.awt.event.ActionEvent;
4 import java.awt.event.ActionListener;
5 import java.rmi.RemoteException;
6
7 import javax.swing.JComboBox;
8 import javax.swing.JOptionPane;
9 import javax.swing.JSpinner;
10 import javax.swing.JTextField;
11
12 import nl.tudelft.goal.ut2004.util.Team;
13 import nl.tudelft.goal.ut2004.visualizer.connection.AddBotCommand;
14 import nl.tudelft.goal.ut2004.visualizer.connection.EnvironmentService;
15 import nl.tudelft.goal.ut2004.visualizer.gui.widgets.WaypointBox;
16 import nl.tudelft.goal.ut2004.visualizer.util.SelectableEnvironment;
17
18 import eis.exceptions.ManagementException;
19
20 public class AddUnrealGoalBotAction implements ActionListener {
21
22 private final JTextField botName;
23 private final nl.tudelft.goal.ut2004.visualizer.gui.widgets.WaypointBox location;
24 private final JSpinner skill;
25 private final JComboBox teamList;
26 private final JComboBox environmentList;
27
28 public AddUnrealGoalBotAction(JTextField botName, WaypointBox location,
29 JSpinner skill, JComboBox teamList, JComboBox environmentList) {
30 this.botName = botName;
31 this.location = location;
32 this.skill = skill;
33 this.teamList = teamList;
34 this.environmentList = environmentList;
35 }
36
37 @Override
38 public void actionPerformed(ActionEvent e) {
39
40 SelectableEnvironment se = (SelectableEnvironment) environmentList
41 .getSelectedItem();
42 final EnvironmentService environement = se.getItem();
43
44 final AddBotCommand addBot = new AddBotCommand();
45 addBot.setBotName(botName.getText());
46 addBot.setSkill((Integer) skill.getValue());
47 addBot.setTeam((Team) teamList.getSelectedItem());
48
49
50 new Thread(new Runnable() {
51
52 @Override
53 public void run() {
54 try {
55 environement.addBot(addBot);
56 } catch (RemoteException e1) {
57 e1.printStackTrace();
58
59 JOptionPane
60 .showMessageDialog(
61 null,
62 "We could not connect to the Unreal Goal environment. A stack strace has been printed to your console.",
63 "An Error has Occured",
64 JOptionPane.ERROR_MESSAGE);
65
66 } catch (ManagementException e2) {
67 e2.printStackTrace();
68 JOptionPane
69 .showMessageDialog(
70 null,
71 "The environment was unable to add a bot. A stack strace has been printed to your console.",
72 "An Error has Occured",
73 JOptionPane.ERROR_MESSAGE);
74 }
75 }
76 }).start();
77 }
78
79 }