Commit d06e01a9 authored by Benedikt Kleinmeier's avatar Benedikt Kleinmeier
Browse files

In "ActionRandomPedestrianDialog.java", added text field "firstPedIdField"...

In "ActionRandomPedestrianDialog.java", added text field "firstPedIdField" because "topography.getNextDynamicElementId()" does not work
parent 6c6c883e
Pipeline #255587 passed with stages
in 137 minutes and 22 seconds
......@@ -56,6 +56,7 @@ public class ActionPlaceRandomPedestrians extends TopographyAction {
double groupMembershipRatio = dialog.getGroupMembershipRatio();
BinomialDistribution binomialDistribution = new BinomialDistribution(BINOMIAL_DISTRIBUTION_SUCCESS_VALUE, groupMembershipRatio);
int firstPedId = dialog.getFirstPedId();
int numOfPeds = dialog.getNumOfPeds();
int createdPeds = 0;
......@@ -64,7 +65,8 @@ public class ActionPlaceRandomPedestrians extends TopographyAction {
VCircle newPosition = new VCircle(point.getX(), point.getY(), this.agentRadius);
if (checkOverlap(newPosition) == false) {
Pedestrian pedestrian = createPedestrian(dialog, topography, random, binomialDistribution, point);
int pedId = firstPedId + i;
Pedestrian pedestrian = createPedestrian(dialog, topography, random, binomialDistribution, point, pedId);
addPedestrianToTopography(pedestrian);
createdPeds++;
}
......@@ -94,10 +96,10 @@ public class ActionPlaceRandomPedestrians extends TopographyAction {
}
@NotNull
private Pedestrian createPedestrian(ActionRandomPedestrianDialog dialog, Topography topography, Random random, BinomialDistribution binomialDistribution, IPoint point) {
private Pedestrian createPedestrian(ActionRandomPedestrianDialog dialog, Topography topography, Random random, BinomialDistribution binomialDistribution, IPoint point, int id) {
AttributesAgent attributesAgent = new AttributesAgent(
topography.getAttributesPedestrian(),
topography.getNextDynamicElementId());
id);
Pedestrian pedestrian = new Pedestrian(attributesAgent, random);
pedestrian.setPosition(new VPoint(point));
......
......@@ -20,6 +20,7 @@ public class ActionRandomPedestrianDialog {
public enum TARGET_OPTION { EMPTY, RANDOM, USE_LIST }
// Member Variables
private JTextField firstPedIdField;
private JTextField numberOfPedsField;
private JTextField boundaryRectangleField;
private JTextField targetsField;
......@@ -34,6 +35,7 @@ public class ActionRandomPedestrianDialog {
private JPanel panelRadioButtons;
private boolean valid;
private int firstPedId;
private int numOfPeds;
private Rectangle2D.Double boundaryRectangle;
private LinkedList<Integer> targetList;
......@@ -45,6 +47,7 @@ public class ActionRandomPedestrianDialog {
public ActionRandomPedestrianDialog() {
valid = false;
firstPedId = 1;
numOfPeds = 10;
boundaryRectangle = new Rectangle2D.Double();
targetList = new LinkedList<>();
......@@ -60,6 +63,21 @@ public class ActionRandomPedestrianDialog {
private void createGuiElements() {
firstPedIdField = new JTextField(String.format(Locale.US, "%d", firstPedId), 15);
firstPedIdField.setHorizontalAlignment(JTextField.RIGHT);
firstPedIdField.getDocument().addDocumentListener(new SimpleDocumentListener() {
@Override
public void handle(DocumentEvent e) {
String text = firstPedIdField.getText();
try {
firstPedId = Integer.parseInt(text);
setValid(true, firstPedIdField);
} catch (Exception ex){
setValid(false, firstPedIdField);
}
}
});
numberOfPedsField = new JTextField(String.format(Locale.US, "%d", numOfPeds), 15);
numberOfPedsField.setHorizontalAlignment(JTextField.RIGHT);
numberOfPedsField.getDocument().addDocumentListener(new SimpleDocumentListener() {
......@@ -187,6 +205,9 @@ public class ActionRandomPedestrianDialog {
int col0 = 0;
int col1 = 1;
panelWindow.add(new JLabel("First Pedestrian Id"), c(GridBagConstraints.HORIZONTAL, col0, row));
panelWindow.add(firstPedIdField, c(GridBagConstraints.HORIZONTAL, col1, row++));
panelWindow.add(new JLabel("Set Number of Pedestrians"), c(GridBagConstraints.HORIZONTAL, col0, row));
panelWindow.add(numberOfPedsField, c(GridBagConstraints.HORIZONTAL, col1, row++));
......@@ -233,6 +254,10 @@ public class ActionRandomPedestrianDialog {
return valid;
}
public int getFirstPedId() {
return firstPedId;
}
public int getNumOfPeds() {
return numOfPeds;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment