-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSimSettings.java
124 lines (93 loc) · 4.33 KB
/
SimSettings.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import javax.swing.*;
public class SimSettings {
private JLabel heightLabel;
private JLabel widthLabel;
private JLabel antCountLabel;
private JLabel brightnessLabel;
private JLabel decayLabel;
private JPanel mainPanel;
private JSlider decaySlider;
private JSlider brightnessSlider;
private JFormattedTextField widthField;
private JFormattedTextField heightField;
private JButton confirm;
private JSpinner antCountSpinner;
private JLabel title;
private JFrame frame;
public SimSettings() {
frame = new JFrame("Make Sim");
final SimSettings launcher = this;
frame.setContentPane(launcher.mainPanel);
frame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
frame.pack();
confirm.setText("make 'em run");
widthField.setEnabled(true);
heightField.setEnabled(true);
System.out.println(Simulation.simulations == null);
System.out.println(launcher.widthField.getValue());
launcher.confirm.addActionListener(e -> {
Integer width = null, height = null, ants = null;
float decay = 0, brightness = 0;
try {
width = Integer.parseInt(launcher.widthField.getText().replaceAll(" ",""));
height = Integer.parseInt(launcher.heightField.getText().replaceAll(" ", ""));
ants = (int) launcher.antCountSpinner.getValue();
decay = (float) launcher.decaySlider.getValue() / decaySlider.getMaximum();
brightness = launcher.brightnessSlider.getValue() / (100f*brightnessSlider.getMaximum());
} catch (Exception ex) {ex.printStackTrace();}
if (width != null && height != null && ants != null) {
Plateau p = new Plateau(width, height, ants, decay, brightness);
Simulation.make(p);
for (int j = 0; j < p.getFourmis().length; j++) {
p.addFourmi(new Fourmi(p, true, new int[] { (int) (3 * Math.random() + 1), 1 }, true));
}
System.out.println(p);
hide();
}
});
}
public SimSettings(Simulation sim) {
frame = new JFrame("Edit sim: " + sim.getId());
final SimSettings launcher = this;
frame.setContentPane(launcher.mainPanel);
frame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
frame.pack();
confirm.setText("Save it");
widthField.setEnabled(false);
heightField.setEnabled(false);
System.out.println(Simulation.simulations == null);
System.out.println(launcher.widthField.getValue());
decaySlider.setValue((int)(decaySlider.getMaximum()*sim.getPlateau().getDecayRate()));
brightnessSlider.setValue((int)(100f*brightnessSlider.getMaximum()*sim.getPlateau().getBrightnessThreshold()));
widthField.setValue(String.valueOf(sim.getPlateau().getWidth()));
heightField.setValue(String.valueOf(sim.getPlateau().getHeight()));
antCountSpinner.setValue(sim.getPlateau().getFourmis().length);
launcher.confirm.addActionListener(e -> {
Integer width = null, height = null, ants = null;
float decay = 0, brightness = 0;
try {
width = Integer.parseInt(launcher.widthField.getText());
height = Integer.parseInt(launcher.heightField.getText());
ants = (int) launcher.antCountSpinner.getValue();
decay = (float) launcher.decaySlider.getValue() / (100f*decaySlider.getMaximum());
brightness = launcher.brightnessSlider.getValue() / brightnessSlider.getMaximum();
} catch (Exception ex) {ex.printStackTrace();}
if (width != null && height != null && ants != null) {
sim.stop();
sim.getPlateau().setBrightnessThreshold(brightness);
sim.getPlateau().setDecayRate(decay);
Fourmi[] f = new Fourmi[ants];
for (int i = 0; i<f.length && i<sim.getPlateau().getFourmis().length; ++i)
f[i] = sim.getPlateau().getFourmis()[i];
sim.getPlateau().setFourmis(f);
sim.start();
}
});
}
public void pop() {
frame.setVisible(true);
}
public void hide() {
frame.setVisible(false);
}
}