代码合并
This commit is contained in:
parent
1d5f0aad08
commit
d5cd1a6b3d
|
@ -1,3 +1,4 @@
|
||||||
|
|
||||||
package net.sf.robocode.ui.dialog;
|
package net.sf.robocode.ui.dialog;
|
||||||
|
|
||||||
|
|
||||||
|
@ -31,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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -59,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);
|
||||||
|
@ -75,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);
|
||||||
|
@ -84,8 +95,11 @@ public class TeamCreator extends JDialog implements WizardListener {
|
||||||
return robotSelectionPanel;
|
return robotSelectionPanel;
|
||||||
}
|
}
|
||||||
|
|
||||||
private WizardCardPanel getWizardPanel() {
|
//新建一个嵌入板
|
||||||
if (wizardPanel == null) {
|
private WizardCardPanel getWizardPanel()
|
||||||
|
{
|
||||||
|
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");
|
||||||
|
@ -93,23 +107,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();
|
||||||
|
@ -127,12 +145,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);
|
||||||
|
|
||||||
|
@ -150,10 +170,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) {}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
|
||||||
package net.sf.robocode.ui.dialog;
|
package net.sf.robocode.ui.dialog;
|
||||||
|
|
||||||
|
|
||||||
|
@ -17,6 +18,7 @@ import java.net.URL;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
public class TeamCreatorOptionsPanel extends WizardPanel {
|
public class TeamCreatorOptionsPanel extends WizardPanel {
|
||||||
private TeamCreator teamCreator;
|
private TeamCreator teamCreator;
|
||||||
|
@ -39,16 +41,20 @@ public class TeamCreatorOptionsPanel extends WizardPanel {
|
||||||
|
|
||||||
private String teamPackage;
|
private String teamPackage;
|
||||||
|
|
||||||
private class EventHandler implements ComponentListener, DocumentListener {
|
private class EventHandler implements ComponentListener, DocumentListener
|
||||||
public void insertUpdate(DocumentEvent e) {
|
{
|
||||||
|
public void insertUpdate(DocumentEvent e)
|
||||||
|
{
|
||||||
fireStateChanged();
|
fireStateChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void changedUpdate(DocumentEvent e) {
|
public void changedUpdate(DocumentEvent e)
|
||||||
|
{
|
||||||
fireStateChanged();
|
fireStateChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeUpdate(DocumentEvent e) {
|
public void removeUpdate(DocumentEvent e)
|
||||||
|
{
|
||||||
fireStateChanged();
|
fireStateChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,32 +65,38 @@ public class TeamCreatorOptionsPanel extends WizardPanel {
|
||||||
public void componentShown(ComponentEvent e) {
|
public void componentShown(ComponentEvent e) {
|
||||||
List<IRobotSpecItem> selectedRobots;
|
List<IRobotSpecItem> selectedRobots;
|
||||||
|
|
||||||
if (teamCreator != null) {
|
if (teamCreator != null)
|
||||||
|
{
|
||||||
selectedRobots = teamCreator.getRobotSelectionPanel().getSelectedRobots();
|
selectedRobots = teamCreator.getRobotSelectionPanel().getSelectedRobots();
|
||||||
} else {
|
} else
|
||||||
|
{
|
||||||
selectedRobots = teamPackager.getRobotSelectionPanel().getSelectedRobots();
|
selectedRobots = teamPackager.getRobotSelectionPanel().getSelectedRobots();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (selectedRobots != null) {
|
if (selectedRobots != null)
|
||||||
|
{
|
||||||
IRobotSpecItem robotSpecification = selectedRobots.get(0);
|
IRobotSpecItem robotSpecification = selectedRobots.get(0);
|
||||||
|
|
||||||
getTeamNameLabel().setText("Please choose a name for your team: (Must be a valid Java classname)");
|
getTeamNameLabel().setText("Please choose a name for your team: (Must be a valid Java classname)");
|
||||||
getTeamNameField().setText(robotSpecification.getShortClassName() + "Team");
|
getTeamNameField().setText(robotSpecification.getShortClassName() + "Team");
|
||||||
getTeamPackageLabel().setText(robotSpecification.getFullPackage() + ".");
|
getTeamPackageLabel().setText(robotSpecification.getFullPackage() + ".");
|
||||||
teamPackage = robotSpecification.getFullPackage();
|
teamPackage = robotSpecification.getFullPackage();
|
||||||
if (teamPackage != null) {
|
if (teamPackage != null)
|
||||||
|
{
|
||||||
teamPackage += ".";
|
teamPackage += ".";
|
||||||
}
|
}
|
||||||
|
|
||||||
String d = robotSpecification.getDescription();
|
String d = robotSpecification.getDescription();
|
||||||
|
|
||||||
if (d == null) {
|
if (d == null)
|
||||||
|
{
|
||||||
d = "";
|
d = "";
|
||||||
}
|
}
|
||||||
getDescriptionArea().setText(d);
|
getDescriptionArea().setText(d);
|
||||||
String a = robotSpecification.getAuthorName();
|
String a = robotSpecification.getAuthorName();
|
||||||
|
|
||||||
if (a == null) {
|
if (a == null)
|
||||||
|
{
|
||||||
a = "";
|
a = "";
|
||||||
}
|
}
|
||||||
getAuthorField().setText(a);
|
getAuthorField().setText(a);
|
||||||
|
@ -303,11 +315,7 @@ public class TeamCreatorOptionsPanel extends WizardPanel {
|
||||||
return teamPackageLabel;
|
return teamPackageLabel;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 得到队伍包
|
|
||||||
*
|
|
||||||
* @return 返回一个字符串
|
|
||||||
*/
|
|
||||||
public String getTeamPackage() {
|
public String getTeamPackage() {
|
||||||
return (teamPackage != null) ? teamPackage : ".";
|
return (teamPackage != null) ? teamPackage : ".";
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue