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 javax.swing.JButton;
22  import javax.swing.JComboBox;
23  import javax.swing.JDialog;
24  import javax.swing.JLabel;
25  import javax.swing.JList;
26  import javax.swing.JSpinner;
27  import javax.swing.JTextField;
28  import javax.swing.SpinnerNumberModel;
29  
30  import nl.tudelft.goal.ut2004.visualizer.gui.action.AddNativeBotAction;
31  import nl.tudelft.goal.ut2004.visualizer.gui.widgets.WaypointBox;
32  import nl.tudelft.goal.ut2004.visualizer.util.WindowPersistenceHelper;
33  
34  import cz.cuni.amis.pogamut.unreal.communication.worldview.map.IUnrealWaypoint;
35  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.NavPoint;
36  import cz.cuni.amis.utils.exception.PogamutException;
37  
38  /**
39   * Dialog for adding an Epic Bot to the server.
40   * 
41   * @author Lennard de Rijk
42   * 
43   */
44  public class AddNativeBotDialog extends JDialog {
45  
46  	/**
47  	 * Field for the name of the bot.
48  	 */
49  	private JTextField nameField;
50  
51  	/**
52  	 * {@link JSpinner} for the difficulty level of the bot.
53  	 */
54  	private JSpinner levelSpinner;
55  
56  	/**
57  	 * {@link JList} which contains a choice between red or blue team.
58  	 */
59  	private JComboBox teamList;
60  
61  	/**
62  	 * {@link WaypointBox} for choosing the location where the bot should spawn.
63  	 */
64  	private WaypointBox location;
65  
66  	/**
67  	 * Button which adds a bot when clicked.
68  	 */
69  	private JButton addButton;
70  
71  	/**
72  	 * Button which closes this dialog when clicked.
73  	 */
74  	private JButton closeButton;
75  
76  	/**
77  	 * Helper class to persist this window.
78  	 */
79  	private WindowPersistenceHelper persistenceHelper;
80  
81  	/**
82  	 * Creates a {@link AddNativeBotDialog} which allows the user to spawn an
83  	 * Epic Bot.
84  	 * 
85  	 * @param parent
86  	 *            Parent Frame, may be null
87  	 * @param navPoint
88  	 * @throws PogamutException
89  	 *             iff the {@link NavPoint} could not be retrieved from the
90  	 *             server.
91  	 */
92  	public AddNativeBotDialog(Frame parent, IUnrealWaypoint navPoint) {
93  		super(parent, false);
94  
95  		setTitle("Add Native Bot");
96  		setLayout(new FlowLayout());
97  
98  		add(new JLabel("Name"));
99  		this.nameField = new JTextField();
100 		this.nameField.setColumns(15);
101 		add(nameField);
102 
103 		// Add a spinner from 1 to 7 with increments of 1
104 		add(new JLabel("Level"));
105 		SpinnerNumberModel levelModel = new SpinnerNumberModel(4, 1, 7, 1);
106 		this.levelSpinner = new JSpinner(levelModel);
107 		add(levelSpinner);
108 
109 		add(new JLabel("Team"));
110 		this.teamList = new JComboBox(new String[] { "Other", "Red", "Blue" });
111 		this.teamList.setSelectedIndex(0);
112 		add(teamList);
113 
114 		location = new WaypointBox();
115 		location.setSelected(navPoint);
116 		add(location);
117 
118 		this.addButton = new JButton("Add Bot");
119 		addButton.addActionListener(new AddNativeBotAction(nameField, location, levelSpinner, teamList));
120 		add(addButton);
121 
122 		setSize(400, 125);
123 
124 		// Setup persistence
125 		persistenceHelper = new WindowPersistenceHelper(this);
126 		persistenceHelper.load();
127 	}
128 }