Permalink
Browse files

Level editor string comparison fixes, and a few other refactorings

  • Loading branch information...
Alberth289346 committed Dec 2, 2016
1 parent 14f293b commit 546cf31104ee0c1924af89bc504a689443fd1df7
@@ -54,7 +54,7 @@ this software and associated documentation files (the "Software"), to deal in
FileChooser fileChooser = new FileChooser(this);
public Gui() {
- List<Image> icons = new ArrayList<Image>();
+ List<Image> icons = new ArrayList<>();
icons.add(Toolkit.getDefaultToolkit().getImage(
ClassLoader.getSystemResource("icon256.png")));
icons.add(Toolkit.getDefaultToolkit().getImage(
@@ -76,6 +76,7 @@ public Gui() {
setSize(800, 600);
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
addWindowListener(new WindowAdapter() {
+ @Override
public void windowClosing(WindowEvent event) {
onExit();
}
@@ -67,6 +67,7 @@ public Menu(JFrame frame) {
// new
fileNew.addActionListener(new ActionListener() {
+ @Override
public void actionPerformed(ActionEvent e) {
var.setDefault();
var.setAllDiseasesAvailable();
@@ -75,6 +76,7 @@ public void actionPerformed(ActionEvent e) {
// open
fileOpen.addActionListener(new ActionListener() {
+ @Override
public void actionPerformed(ActionEvent e) {
File file = (fileChooser.open());
@@ -103,6 +105,7 @@ public void actionPerformed(ActionEvent e) {
// save as
fileSaveAs.addActionListener(new ActionListener() {
+ @Override
public void actionPerformed(ActionEvent e) {
try {
File file = (fileChooser.saveAs());
@@ -116,6 +119,7 @@ public void actionPerformed(ActionEvent e) {
});
about.addActionListener(new ActionListener() {
+ @Override
public void actionPerformed(ActionEvent e) {
JOptionPane aboutPane = new JOptionPane("Version: "
+ Main.VERSION + "\n\n"
@@ -425,34 +425,39 @@ public void saveAs(File file) {
write.write("----------------------- Emergency Control --------------------------");
write.newLine();
write.newLine();
- if (Emergency.emergencyMode == 0) {
- write.write("#emergency_control[0].Random 0");
- write.newLine();
- } else if (Emergency.emergencyMode == 1) {
- write.write("#emergency_control[0].Mean.Variance "
- + TabEmergencies.emergencyInterval + " "
- + TabEmergencies.emergencyIntervalVariance);
- write.newLine();
- } else if (Emergency.emergencyMode == 2) {
- for (int i = 0; i < TabEmergencies.emergencyList.size(); i++) {
- write.write("#emergency_control["
- + i
- + "].StartMonth.EndMonth.Min.Max.Illness.PercWin.Bonus "
- + TabEmergencies.emergencyList.get(i).startMonth
- + " "
- + TabEmergencies.emergencyList.get(i).endMonth
- + " "
- + TabEmergencies.emergencyList.get(i).minPatients
- + " "
- + TabEmergencies.emergencyList.get(i).maxPatients
- + " "
- + TabEmergencies.emergencyList.get(i).illness
- + " "
- + TabEmergencies.emergencyList.get(i).percWin
- + " "
- + TabEmergencies.emergencyList.get(i).bonus);
+ switch (Emergency.emergencyMode) {
+ case 0:
+ write.write("#emergency_control[0].Random 0");
write.newLine();
- }
+ break;
+ case 1:
+ write.write("#emergency_control[0].Mean.Variance "
+ + TabEmergencies.emergencyInterval + " "
+ + TabEmergencies.emergencyIntervalVariance);
+ write.newLine();
+ break;
+ case 2:
+ for (int i = 0; i < TabEmergencies.emergencyList.size(); i++) {
+ write.write("#emergency_control["
+ + i
+ + "].StartMonth.EndMonth.Min.Max.Illness.PercWin.Bonus "
+ + TabEmergencies.emergencyList.get(i).startMonth
+ + " "
+ + TabEmergencies.emergencyList.get(i).endMonth
+ + " "
+ + TabEmergencies.emergencyList.get(i).minPatients
+ + " "
+ + TabEmergencies.emergencyList.get(i).maxPatients
+ + " "
+ + TabEmergencies.emergencyList.get(i).illness
+ + " "
+ + TabEmergencies.emergencyList.get(i).percWin
+ + " "
+ + TabEmergencies.emergencyList.get(i).bonus);
+ write.newLine();
+ } break;
+ default:
+ break;
}
write.newLine();
write.newLine();
@@ -625,7 +630,7 @@ public void readFromFile(String line, String parameter, String variable) {
// we check the position of each parameter, so we know which value
// belongs to which parameter.
if ((line.split("[\\.\\s+]")[i]).matches(parameter))
- if (variable != "interest") {
+ if (!"interest".equals(variable)) {
// to get only the actual value, split along "\\s+"
// whitespaces.
@@ -682,7 +687,7 @@ public void readTableFromFile(String line, String parameter, String variable) {
for (int i = 1; i < (parameterCount); i++) {
// gbv.SalaryAdd[] has its parameter (SalaryAdd) before the
// brackets
- if (parameter == "SalaryAdd") {
+ if ("SalaryAdd".equals(parameter)) {
if ((line.split("[\\.\\s+]")[i]).matches(parameter
+ "\\[\\d\\]")) {
// split the line to get the value inside [ ] (the
@@ -80,13 +80,15 @@ public TabAwards() {
.setToolTipText("Sell more than this number of cans to win the award");
awards.add(cansOfCokeTF);
cansOfCokeTF.addFocusListener(new FocusListener() {
+ @Override
public void focusGained(FocusEvent e) {
JTextField tf = (JTextField) e.getComponent();
tf.selectAll();
Gui.tempValue = tf.getText();
}
+ @Override
public void focusLost(FocusEvent e) {
try {
int input = Integer.parseInt(((JTextField) e.getComponent())
@@ -107,13 +109,15 @@ public void focusLost(FocusEvent e) {
cansOfCokeBonusLabel.setToolTipText("Cash bonus for this award");
awards.add(cansOfCokeBonusTF);
cansOfCokeBonusTF.addFocusListener(new FocusListener() {
+ @Override
public void focusGained(FocusEvent e) {
JTextField tf = (JTextField) e.getComponent();
tf.selectAll();
Gui.tempValue = tf.getText();
}
+ @Override
public void focusLost(FocusEvent e) {
try {
int input = Integer.parseInt(((JTextField) e.getComponent())
@@ -137,13 +141,15 @@ public void focusLost(FocusEvent e) {
.setToolTipText("Reputation that is needed through the whole year to win the award");
awards.add(reputationTF);
reputationTF.addFocusListener(new FocusListener() {
+ @Override
public void focusGained(FocusEvent e) {
JTextField tf = (JTextField) e.getComponent();
tf.selectAll();
Gui.tempValue = tf.getText();
}
+ @Override
public void focusLost(FocusEvent e) {
try {
int input = Integer.parseInt(((JTextField) e.getComponent())
@@ -166,13 +172,15 @@ public void focusLost(FocusEvent e) {
reputationBonusLabel.setToolTipText("Cash bonus for this award");
awards.add(reputationBonusTF);
reputationBonusTF.addFocusListener(new FocusListener() {
+ @Override
public void focusGained(FocusEvent e) {
JTextField tf = (JTextField) e.getComponent();
tf.selectAll();
Gui.tempValue = tf.getText();
}
+ @Override
public void focusLost(FocusEvent e) {
try {
int input = Integer.parseInt(((JTextField) e.getComponent())
@@ -196,13 +204,15 @@ public void focusLost(FocusEvent e) {
.setToolTipText("Cash bonus for killing no patients the whole year");
awards.add(noDeathsBonusTF);
noDeathsBonusTF.addFocusListener(new FocusListener() {
+ @Override
public void focusGained(FocusEvent e) {
JTextField tf = (JTextField) e.getComponent();
tf.selectAll();
Gui.tempValue = tf.getText();
}
+ @Override
public void focusLost(FocusEvent e) {
try {
int input = Integer.parseInt(((JTextField) e.getComponent())
Oops, something went wrong.

0 comments on commit 546cf31

Please sign in to comment.