1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package nl.tudelft.goal.ut2004.visualizer.gui.dialogs;
18
19 import java.awt.FlowLayout;
20 import java.awt.Frame;
21 import java.awt.GridLayout;
22 import java.awt.event.ActionEvent;
23 import java.awt.event.ActionListener;
24 import java.util.Collection;
25
26 import javax.swing.DefaultComboBoxModel;
27 import javax.swing.JButton;
28 import javax.swing.JComboBox;
29 import javax.swing.JDialog;
30 import javax.swing.JLabel;
31 import javax.swing.JList;
32 import javax.swing.JOptionPane;
33 import javax.swing.JScrollPane;
34 import javax.swing.JSpinner;
35 import javax.swing.JTextField;
36 import javax.swing.ListSelectionModel;
37 import javax.swing.SpinnerNumberModel;
38 import javax.swing.SwingUtilities;
39
40 import nl.tudelft.goal.ut2004.visualizer.connection.EnvironmentService;
41 import nl.tudelft.goal.ut2004.visualizer.controller.ServerController;
42 import nl.tudelft.goal.ut2004.visualizer.data.EnvironmentData;
43 import nl.tudelft.goal.ut2004.visualizer.gui.action.AddNativeBotAction;
44 import nl.tudelft.goal.ut2004.visualizer.gui.action.AddUnrealGoalBotAction;
45 import nl.tudelft.goal.ut2004.visualizer.gui.widgets.WaypointBox;
46 import nl.tudelft.goal.ut2004.visualizer.util.CollectionEventAdaptor;
47 import nl.tudelft.goal.ut2004.visualizer.util.SelectableEnvironment;
48 import nl.tudelft.goal.ut2004.visualizer.util.SelectableWayPoint;
49 import cz.cuni.amis.pogamut.base3d.worldview.object.Location;
50 import cz.cuni.amis.pogamut.unreal.communication.worldview.map.IUnrealWaypoint;
51 import cz.cuni.amis.pogamut.ut2004.communication.messages.gbcommands.AddBot;
52 import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.NavPoint;
53 import cz.cuni.amis.pogamut.ut2004.communication.worldview.map.Waypoint;
54 import cz.cuni.amis.pogamut.ut2004.server.IUT2004Server;
55 import cz.cuni.amis.utils.collections.CollectionEventListener;
56 import cz.cuni.amis.utils.collections.ObservableSet;
57 import cz.cuni.amis.utils.exception.PogamutException;
58
59
60
61
62
63
64
65 public class AddUnrealGoalBotDialog extends JDialog {
66
67
68
69
70 private JTextField nameField;
71
72
73
74
75 private JSpinner levelSpinner;
76
77
78
79
80 private JComboBox teamList;
81
82
83
84
85 private WaypointBox location;
86
87
88
89
90 private JButton addButton;
91
92
93
94
95 private JButton closeButton;
96
97 private JComboBox environmentList;
98
99
100
101
102
103
104
105
106
107
108
109
110 public AddUnrealGoalBotDialog(Frame parent, IUnrealWaypoint navPoint) {
111 super(parent, false);
112
113 setTitle("Add UnrealGoal bot");
114 setLayout(new FlowLayout());
115
116 add(new JLabel("Name"));
117 this.nameField = new JTextField();
118 this.nameField.setColumns(15);
119 add(nameField);
120
121
122 add(new JLabel("Level"));
123 SpinnerNumberModel levelModel = new SpinnerNumberModel(4, 1, 7, 1);
124 this.levelSpinner = new JSpinner(levelModel);
125 add(levelSpinner);
126
127 add(new JLabel("Team"));
128 this.teamList = new JComboBox(new String[] { "Other", "Red", "Blue" });
129 this.teamList.setSelectedIndex(0);
130 add(teamList);
131
132 location = new WaypointBox();
133 if (navPoint != null)
134 location.setSelected(navPoint);
135 add(location);
136
137 ServerController controller = ServerController.getInstance();
138 EnvironmentData data = controller.getEnvironmentData();
139 ObservableSet<EnvironmentService> clients = data.getEnvironments();
140 Collection<SelectableEnvironment> s = SelectableEnvironment
141 .fromCollection(clients);
142 this.environmentList = new JComboBox(s.toArray());
143 clients.addCollectionListener(new CollectionEventAdaptor<EnvironmentService>() {
144
145 @Override
146 public void postAddEvent(
147 Collection<EnvironmentService> alreadyAdded,
148 final Collection<EnvironmentService> whereWereAdded) {
149 SwingUtilities.invokeLater(new Runnable() {
150
151 @Override
152 public void run() {
153 Collection<SelectableEnvironment> s = SelectableEnvironment
154 .fromCollection(whereWereAdded);
155 environmentList.setModel(new DefaultComboBoxModel(s
156 .toArray()));
157 }
158 });
159 }
160
161 @Override
162 public void postRemoveEvent(
163 Collection<EnvironmentService> alreadyRemoved,
164 final Collection<EnvironmentService> whereWereRemoved) {
165 SwingUtilities.invokeLater(new Runnable() {
166
167 @Override
168 public void run() {
169 Collection<SelectableEnvironment> s = SelectableEnvironment
170 .fromCollection(whereWereRemoved);
171 environmentList.setModel(new DefaultComboBoxModel(s
172 .toArray()));
173 }
174 });
175 }
176 });
177
178 add(environmentList);
179
180 this.addButton = new JButton("Add Bot");
181 addButton.addActionListener(new AddUnrealGoalBotAction(nameField,
182 location, levelSpinner, teamList, environmentList));
183 add(addButton);
184
185 setSize(400, 225);
186 }
187 }