10.12., 9:00 - 11:00: Due to updates GitLab may be unavailable for some minutes between 09:00 and 11:00.

Commit 50f028be authored by Benedikt Kleinmeier's avatar Benedikt Kleinmeier

In "SettingsDialog" fixed "Color by Target Id" (but configured color is still ignored in renderer)

parent 3943b0c5
Pipeline #160577 passed with stages
in 123 minutes and 8 seconds
......@@ -10,16 +10,20 @@ import org.vadere.gui.components.model.DefaultSimulationConfig;
import org.vadere.gui.components.model.SimulationModel;
public class ActionSetPedestrianColor extends ActionSetColor {
private final JComboBox<Integer> comboBox;
private final JComboBox<Integer> comboBox;
public ActionSetPedestrianColor(final String name, final SimulationModel<? extends DefaultSimulationConfig> model, final JPanel coloredPanel,
final JComboBox<Integer> comboBox) {
super(name, model, coloredPanel);
this.comboBox = comboBox;
}
public ActionSetPedestrianColor(final String name, final SimulationModel<? extends DefaultSimulationConfig> model, final JPanel coloredPanel,
final JComboBox<Integer> comboBox) {
super(name, model, coloredPanel);
this.comboBox = comboBox;
}
@Override
protected void saveColor(Color color) {
model.config.setPedestrianColor(comboBox.getSelectedIndex() + 1, color);
}
@Override
protected void saveColor(Color color) {
Integer selectedTargetId = comboBox.getItemAt(comboBox.getSelectedIndex());
if (selectedTargetId != null) {
model.config.setPedestrianColor(selectedTargetId, color);
}
}
}
......@@ -157,14 +157,27 @@ public class SettingsDialog extends JDialog {
final JButton bChange = new JButton(Messages.getString("SettingsDialog.btnEditColor.text"));
final JPanel pPedestrian = new JPanel();
Optional<Color> colorByTargetId = model.config.getColorByTargetId(1);
Integer selectedTargetIdOuter = jComboTargetIds.getItemAt(jComboTargetIds.getSelectedIndex());
if (selectedTargetIdOuter == null) {
selectedTargetIdOuter = 1;
}
Optional<Color> colorByTargetId = model.config.getColorByTargetId(selectedTargetIdOuter);
pPedestrian.setBackground(colorByTargetId.orElseGet(() -> model.config.getPedestrianDefaultColor()));
pPedestrian.setPreferredSize(new Dimension(130, 20));
// When user changes a color, save it in the model.
bChange.addActionListener(new ActionSetPedestrianColor("Set Pedestrian Color", model, pPedestrian,
jComboTargetIds));
// Retrieve configured color from "model" or use default color.
jComboTargetIds.addActionListener(e -> {
Optional<Color> colorByTarget = config.getColorByTargetId(jComboTargetIds.getSelectedIndex() + 1);
Integer selectedTargetIdInner = jComboTargetIds.getItemAt(jComboTargetIds.getSelectedIndex());
if (selectedTargetIdInner == null) {
selectedTargetIdInner = 1;
}
Optional<Color> colorByTarget = config.getColorByTargetId(selectedTargetIdInner);
pPedestrian.setBackground(colorByTarget.orElseGet(() -> model.config.getPedestrianDefaultColor()));
});
colorSettingsPane.add(jComboTargetIds, cc.xy(2, row += NEXT_CELL));
......
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