Merge branch 'zhouhao_branch'
This commit is contained in:
commit
e2dc6a6019
|
@ -32,14 +32,17 @@ public class TeamCreator extends JDialog implements WizardListener {
|
||||||
private RobotSelectionPanel robotSelectionPanel;
|
private RobotSelectionPanel robotSelectionPanel;
|
||||||
private TeamCreatorOptionsPanel teamCreatorOptionsPanel;
|
private TeamCreatorOptionsPanel teamCreatorOptionsPanel;
|
||||||
|
|
||||||
private final int minRobots = 2;
|
private final int minRobots = 2;//每个编队至少两人
|
||||||
private final int maxRobots = 10;
|
private final int maxRobots = 10;//每个编队最多10人
|
||||||
|
|
||||||
private final EventHandler eventHandler = new EventHandler();
|
private final EventHandler eventHandler = new EventHandler();
|
||||||
|
|
||||||
|
//EventHandler具体实现ActionListener接口,实现动作的监听操作
|
||||||
class EventHandler implements ActionListener {
|
class EventHandler implements ActionListener {
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
//e为传入的参数,传入临时变量e,为ActionEvent类型
|
||||||
if (e.getActionCommand().equals("Refresh")) {
|
if (e.getActionCommand().equals("Refresh")) {
|
||||||
|
//执行跟新操作
|
||||||
getRobotSelectionPanel().refreshRobotList(true);
|
getRobotSelectionPanel().refreshRobotList(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -60,9 +63,12 @@ public class TeamCreator extends JDialog implements WizardListener {
|
||||||
return teamCreatorOptionsPanel;
|
return teamCreatorOptionsPanel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//获取创建编队嵌入框中的内容
|
||||||
private JPanel getTeamCreatorContentPane() {
|
private JPanel getTeamCreatorContentPane() {
|
||||||
if (teamCreatorContentPane == null) {
|
if (teamCreatorContentPane == null) {
|
||||||
|
//如果嵌入框内容为空
|
||||||
teamCreatorContentPane = new JPanel();
|
teamCreatorContentPane = new JPanel();
|
||||||
|
//新建嵌入框
|
||||||
teamCreatorContentPane.setLayout(new BorderLayout());
|
teamCreatorContentPane.setLayout(new BorderLayout());
|
||||||
teamCreatorContentPane.add(getWizardController(), BorderLayout.SOUTH);
|
teamCreatorContentPane.add(getWizardController(), BorderLayout.SOUTH);
|
||||||
teamCreatorContentPane.add(getWizardPanel(), BorderLayout.CENTER);
|
teamCreatorContentPane.add(getWizardPanel(), BorderLayout.CENTER);
|
||||||
|
@ -76,8 +82,12 @@ public class TeamCreator extends JDialog implements WizardListener {
|
||||||
return teamCreatorContentPane;
|
return teamCreatorContentPane;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected RobotSelectionPanel getRobotSelectionPanel() {
|
//选择机器人组成编队
|
||||||
if (robotSelectionPanel == null) {
|
protected RobotSelectionPanel getRobotSelectionPanel()
|
||||||
|
{
|
||||||
|
//如果当前选择为空
|
||||||
|
if (robotSelectionPanel == null)
|
||||||
|
{
|
||||||
robotSelectionPanel = net.sf.robocode.core.Container.createComponent(RobotSelectionPanel.class);
|
robotSelectionPanel = net.sf.robocode.core.Container.createComponent(RobotSelectionPanel.class);
|
||||||
robotSelectionPanel.setup(minRobots, maxRobots, false, "Select the robots for this team.", false, true, true,
|
robotSelectionPanel.setup(minRobots, maxRobots, false, "Select the robots for this team.", false, true, true,
|
||||||
false, false, false, null);
|
false, false, false, null);
|
||||||
|
@ -85,8 +95,10 @@ public class TeamCreator extends JDialog implements WizardListener {
|
||||||
return robotSelectionPanel;
|
return robotSelectionPanel;
|
||||||
}
|
}
|
||||||
|
|
||||||
private WizardCardPanel getWizardPanel() {
|
private WizardCardPanel getWizardPanel()
|
||||||
if (wizardPanel == null) {
|
{
|
||||||
|
if (wizardPanel == null)
|
||||||
|
{
|
||||||
wizardPanel = new WizardCardPanel(this);
|
wizardPanel = new WizardCardPanel(this);
|
||||||
wizardPanel.add(getRobotSelectionPanel(), "Select robots");
|
wizardPanel.add(getRobotSelectionPanel(), "Select robots");
|
||||||
wizardPanel.add(getTeamCreatorOptionsPanel(), "Select options");
|
wizardPanel.add(getTeamCreatorOptionsPanel(), "Select options");
|
||||||
|
@ -94,23 +106,27 @@ public class TeamCreator extends JDialog implements WizardListener {
|
||||||
return wizardPanel;
|
return wizardPanel;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initialize() {
|
//窗口初始化
|
||||||
|
public void initialize()
|
||||||
|
{
|
||||||
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
|
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
|
||||||
setTitle("Create a team");
|
setTitle("Create a team");
|
||||||
setContentPane(getTeamCreatorContentPane());
|
setContentPane(getTeamCreatorContentPane());
|
||||||
}
|
}
|
||||||
|
|
||||||
private WizardController getWizardController() {
|
private WizardController getWizardController() {
|
||||||
if (wizardController == null) {
|
if (wizardController == null)
|
||||||
|
{
|
||||||
wizardController = getWizardPanel().getWizardController();
|
wizardController = getWizardPanel().getWizardController();
|
||||||
}
|
}
|
||||||
return wizardController;
|
return wizardController;
|
||||||
}
|
}
|
||||||
|
//添加取消键动作
|
||||||
public void cancelButtonActionPerformed() {
|
public void cancelButtonActionPerformed() {
|
||||||
dispose();
|
dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//添加完成键动作
|
||||||
public void finishButtonActionPerformed() {
|
public void finishButtonActionPerformed() {
|
||||||
try {
|
try {
|
||||||
int rc = createTeam();
|
int rc = createTeam();
|
||||||
|
@ -128,12 +144,14 @@ public class TeamCreator extends JDialog implements WizardListener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//将创建的编队写入数据库
|
||||||
public int createTeam() throws IOException {
|
public int createTeam() throws IOException {
|
||||||
File file = new File(repositoryManager.getRobotsDirectory(),
|
File file = new File(repositoryManager.getRobotsDirectory(),
|
||||||
teamCreatorOptionsPanel.getTeamPackage().replace('.', File.separatorChar)
|
teamCreatorOptionsPanel.getTeamPackage().replace('.', File.separatorChar)
|
||||||
+ teamCreatorOptionsPanel.getTeamNameField().getText() + ".team");
|
+ teamCreatorOptionsPanel.getTeamNameField().getText() + ".team");
|
||||||
|
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
|
//如果当前编队已经存在
|
||||||
int ok = JOptionPane.showConfirmDialog(this, file + " already exists. Are you sure you want to replace it?",
|
int ok = JOptionPane.showConfirmDialog(this, file + " already exists. Are you sure you want to replace it?",
|
||||||
"Warning", JOptionPane.YES_NO_CANCEL_OPTION);
|
"Warning", JOptionPane.YES_NO_CANCEL_OPTION);
|
||||||
|
|
||||||
|
@ -151,10 +169,13 @@ public class TeamCreator extends JDialog implements WizardListener {
|
||||||
String webPageFieldString = teamCreatorOptionsPanel.getWebpageField().getText();
|
String webPageFieldString = teamCreatorOptionsPanel.getWebpageField().getText();
|
||||||
|
|
||||||
if (webPageFieldString != null && webPageFieldString.length() > 0) {
|
if (webPageFieldString != null && webPageFieldString.length() > 0) {
|
||||||
try {
|
try
|
||||||
|
{
|
||||||
webPageUrl = new URL(webPageFieldString);
|
webPageUrl = new URL(webPageFieldString);
|
||||||
} catch (MalformedURLException e) {
|
} catch (MalformedURLException e)
|
||||||
try {
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
webPageUrl = new URL("http://" + webPageFieldString);
|
webPageUrl = new URL("http://" + webPageFieldString);
|
||||||
teamCreatorOptionsPanel.getWebpageField().setText(webPageUrl.toString());
|
teamCreatorOptionsPanel.getWebpageField().setText(webPageUrl.toString());
|
||||||
} catch (MalformedURLException ignored) {}
|
} catch (MalformedURLException ignored) {}
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue