View Javadoc

1   /*
2    * Copyright (C) 2010 Unreal Visualizer Authors
3    *
4    * This program is free software: you can redistribute it and/or modify
5    * it under the terms of the GNU General Public License as published by
6    * the Free Software Foundation, either version 3 of the License, or
7    * (at your option) any later version.
8    *
9    * This program is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   * GNU General Public License for more details.
13   *
14   * You should have received a copy of the GNU General Public License
15   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
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.JButton;
27  import javax.swing.JComboBox;
28  import javax.swing.JDialog;
29  import javax.swing.JLabel;
30  import javax.swing.JList;
31  import javax.swing.JOptionPane;
32  import javax.swing.JScrollPane;
33  import javax.swing.JSpinner;
34  import javax.swing.JTextField;
35  import javax.swing.ListSelectionModel;
36  import javax.swing.SpinnerNumberModel;
37  
38  import nl.tudelft.goal.ut2004.visualizer.controller.ServerController;
39  import nl.tudelft.goal.ut2004.visualizer.gui.action.AddNativeBotAction;
40  import nl.tudelft.goal.ut2004.visualizer.gui.widgets.WaypointBox;
41  import nl.tudelft.goal.ut2004.visualizer.util.SelectableWayPoint;
42  
43  import cz.cuni.amis.pogamut.base3d.worldview.object.Location;
44  import cz.cuni.amis.pogamut.unreal.communication.worldview.map.IUnrealWaypoint;
45  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbcommands.AddBot;
46  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.NavPoint;
47  import cz.cuni.amis.pogamut.ut2004.communication.worldview.map.Waypoint;
48  import cz.cuni.amis.pogamut.ut2004.server.IUT2004Server;
49  import cz.cuni.amis.utils.exception.PogamutException;
50  
51  /**
52   * Dialog for adding an Epic Bot to the server.
53   * 
54   * @author Lennard de Rijk
55   * 
56   */
57  public class AddNativeBotDialog extends JDialog {
58  
59  	/**
60  	 * Field for the name of the bot.
61  	 */
62  	private JTextField nameField;
63  
64  	/**
65  	 * {@link JSpinner} for the difficulty level of the bot.
66  	 */
67  	private JSpinner levelSpinner;
68  
69  	/**
70  	 * {@link JList} which contains a choice between red or blue team.
71  	 */
72  	private JComboBox teamList;
73  
74  	/**
75  	 * {@link WaypointBox} for choosing the location where the bot should spawn.
76  	 */
77  	private WaypointBox location;
78  
79  	/**
80  	 * Button which adds a bot when clicked.
81  	 */
82  	private JButton addButton;
83  
84  	/**
85  	 * Button which closes this dialog when clicked.
86  	 */
87  	private JButton closeButton;
88  
89  	/**
90  	 * Creates a {@link AddNativeBotDialog} which allows the user to spawn an
91  	 * Epic Bot.
92  	 * 
93  	 * @param parent
94  	 *            Parent Frame, may be null
95  	 * @param navPoint
96  	 * @throws PogamutException
97  	 *             iff the {@link NavPoint} could not be retrieved from the
98  	 *             server.
99  	 */
100 	public AddNativeBotDialog(Frame parent, IUnrealWaypoint navPoint) {
101 		super(parent, false);
102 
103 		setTitle("Add Native Bot");
104 		setLayout(new FlowLayout());
105 
106 		add(new JLabel("Name"));
107 		this.nameField = new JTextField();
108 		this.nameField.setColumns(15);
109 		add(nameField);
110 
111 		// Add a spinner from 1 to 7 with increments of 1
112 		add(new JLabel("Level"));
113 		SpinnerNumberModel levelModel = new SpinnerNumberModel(4, 1, 7, 1);
114 		this.levelSpinner = new JSpinner(levelModel);
115 		add(levelSpinner);
116 
117 		add(new JLabel("Team"));
118 		this.teamList = new JComboBox(new String[] {"Other", "Red", "Blue" });
119 		this.teamList.setSelectedIndex(0);
120 		add(teamList);
121 
122 		location = new WaypointBox();
123 		location.setSelected(navPoint);
124 		add(location);
125 
126 		this.addButton = new JButton("Add Bot");
127 		addButton.addActionListener(new AddNativeBotAction(nameField, location,
128 				levelSpinner, teamList));
129 		add(addButton);
130 
131 		setSize(400, 125);
132 	}
133 }