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

In "SettingsDialog", added radio button "Color by Self Category"

Watch out: The color settings are stored in "model.config",
but are NOT used during rendering at the moment!
parent 73a83cd2
......@@ -298,6 +298,7 @@ SettingsDialog.lblTargetChanger.text=Target Changer
SettingsDialog.lblStair.text=Stair
SettingsDialog.lblPedestrianNoTarget.text=Without Target
SettingsDialog.lblTargetColoring.text=Coloring by Target
SettingsDialog.lblSelfCategoryColoring.text=Coloring by Self Category
ProjectView.menuOpenFloorFieldFile.title=Add Floor Field File...
ProjectView.btnDrawVoronoiDiagram.tooltip=Draw and display a Voronoi Diagram
......
......@@ -293,6 +293,7 @@ SettingsDialog.lblTargetChanger.text=Ziel\u00e4nderung
SettingsDialog.lblStair.text=Treppe
SettingsDialog.lblPedestrianNoTarget.text=Ohne Ziel
SettingsDialog.lblTargetColoring.text=F\u00e4rbung nach Ziel
SettingsDialog.lblSelfCategoryColoring.text=F\u00e4rbung nach "Self Category"
SettingsDialog.menuOpenFloorFieldFile.title=Floor Field-Datei hinzuf\u00fcgen...
SettingsDialog.btnDrawVoronoiDiagram.tooltip=Voronoi-Diagramm zeichnen und anzeigen
SettingsDialog.chbLogo.text=VADERE-Logo anzeigen
......
package org.vadere.gui.components.control.simulation;
import org.vadere.gui.components.model.DefaultSimulationConfig;
import org.vadere.gui.components.model.SimulationModel;
import org.vadere.state.psychology.cognition.SelfCategory;
import javax.swing.*;
import java.awt.*;
public class ActionSetSelfCategoryColor extends ActionSetColor {
private final JComboBox<SelfCategory> comboBox;
public ActionSetSelfCategoryColor(final String name, final SimulationModel<? extends DefaultSimulationConfig> model, final JPanel coloredPanel,
final JComboBox<SelfCategory> comboBox) {
super(name, model, coloredPanel);
this.comboBox = comboBox;
}
@Override
protected void saveColor(Color color) {
SelfCategory selfCategory = comboBox.getItemAt(comboBox.getSelectedIndex());
if (selfCategory != null) {
model.config.setSelfCategoryColor(selfCategory, color);
}
}
}
package org.vadere.gui.components.model;
public enum AgentColoring {
TARGET, RANDOM, GROUP, EVACUATION_TIMES, PREDICATE;
TARGET, RANDOM, GROUP, EVACUATION_TIMES, PREDICATE, SELF_CATEGORY;
}
......@@ -7,6 +7,7 @@ import java.util.Optional;
import java.util.TreeMap;
import org.apache.commons.configuration2.Configuration;
import org.vadere.state.psychology.cognition.SelfCategory;
import org.vadere.util.config.VadereConfig;
import org.vadere.util.visualization.ColorHelper;
......@@ -41,6 +42,7 @@ public class DefaultSimulationConfig extends DefaultConfig {
protected final Color pedestrianDefaultColor = new Color(76, 114, 202);
private Map<Integer, Color> pedestrianColors = new TreeMap<>();
private Map<Integer, Color> randomColors = new HashMap<>();
private Map<Integer, Color> selfCategoryColors = new HashMap<>();
private double gridWidth = CONFIG.getDouble("ProjectView.cellWidth");
private final double MIN_CELL_WIDTH = CONFIG.getDouble("ProjectView.minCellWidth");
private final double MAX_CELL_WIDTH = CONFIG.getDouble("ProjectView.maxCellWidth");
......@@ -55,6 +57,7 @@ public class DefaultSimulationConfig extends DefaultConfig {
this.randomColors = new HashMap<>();
this.pedestrianColors = new HashMap<>();
this.selfCategoryColors = new HashMap<>();
for (Map.Entry<Integer, Color> entry : config.pedestrianColors.entrySet()) {
this.pedestrianColors.put(new Integer(entry.getKey()), new Color(entry.getValue().getRed(), entry
......@@ -294,6 +297,21 @@ public class DefaultSimulationConfig extends DefaultConfig {
return randomColors.get(pedId);
}
public void setSelfCategoryColor(SelfCategory selfCategory, final Color color) {
this.selfCategoryColors.put(selfCategory.ordinal(), color);
setChanged();
}
public Color getSelfCategoryColor(SelfCategory selfCategory) {
Color color = getPedestrianDefaultColor();
if (selfCategoryColors.containsKey(selfCategory.ordinal())) {
color = selfCategoryColors.get(selfCategory.ordinal());
}
return color;
}
public void setGridWidth(final double gridWidth) {
this.gridWidth = gridWidth;
}
......
......@@ -11,6 +11,7 @@ import org.vadere.gui.components.model.SimulationModel;
import org.vadere.gui.components.utils.Messages;
import org.vadere.gui.components.utils.SwingUtils;
import org.vadere.gui.postvisualization.control.ActionCloseSettingDialog;
import org.vadere.state.psychology.cognition.SelfCategory;
import org.vadere.state.scenario.Target;
import org.vadere.util.config.VadereConfig;
......@@ -35,6 +36,7 @@ public class SettingsDialog extends JDialog {
protected JLayeredPane agentColorSettingsPane;
private JLayeredPane otherSettingsPane;
private JComboBox<Integer> jComboTargetIds;
private JComboBox<SelfCategory> jComboSelfCategories;
protected ButtonGroup group;
public SettingsDialog(final SimulationModel<? extends DefaultSimulationConfig> model) {
......@@ -162,7 +164,7 @@ public class SettingsDialog extends JDialog {
CellConstraints cc = new CellConstraints();
FormLayout pedColorLayout = new FormLayout("5dlu, pref, 2dlu, pref, 2dlu, pref:grow, 2dlu, pref, 2dlu, pref, 5dlu",
createCellsWithSeparators(6));
createCellsWithSeparators(8));
colorSettingsPane.setLayout(pedColorLayout);
colorSettingsPane.setBorder(BorderFactory.createTitledBorder(Messages.getString("SettingsDialog.pedcolors.border.text")));
......@@ -170,8 +172,8 @@ public class SettingsDialog extends JDialog {
jComboTargetIds = createTargetIdsComboBoxAndAddIds();
jComboTargetIds.setSelectedIndex(0);
final JButton bChange = new JButton(Messages.getString("SettingsDialog.btnEditColor.text"));
final JPanel pPedestrian = new JPanel();
final JButton bChangeTargetColor = new JButton(Messages.getString("SettingsDialog.btnEditColor.text"));
final JPanel pByTargetId = new JPanel();
Integer selectedTargetIdOuter = jComboTargetIds.getItemAt(jComboTargetIds.getSelectedIndex());
if (selectedTargetIdOuter == null) {
......@@ -198,16 +200,44 @@ public class SettingsDialog extends JDialog {
model.notifyObservers();
});
JRadioButton selfCategoryColoring = new JRadioButton(Messages.getString("SettingsDialog.lblSelfCategoryColoring.text")+ ":");
model.setAgentColoring(AgentColoring.SELF_CATEGORY);
selfCategoryColoring.addItemListener(e -> {
model.setAgentColoring(AgentColoring.SELF_CATEGORY);
model.notifyObservers();
});
jComboSelfCategories = createSelfCategoriesComboBox();
jComboSelfCategories.setSelectedIndex(0);
final JButton bChangeSelfCategoryColor = new JButton(Messages.getString("SettingsDialog.btnEditColor.text"));
final JPanel pBySelfCategory = new JPanel();
SelfCategory selectedSelfCategory = jComboSelfCategories.getItemAt(jComboTargetIds.getSelectedIndex());
Color colorBySelfCategory = model.config.getSelfCategoryColor(selectedSelfCategory);
pBySelfCategory.setBackground(colorBySelfCategory);
pBySelfCategory.setPreferredSize(new Dimension(130, 20));
// When user changes a color, save it in the model.
bChangeSelfCategoryColor.addActionListener(new ActionSetSelfCategoryColor("Set Self Category Color", model, pBySelfCategory,
jComboSelfCategories));
// Retrieve configured color from "model" or use default color.
jComboSelfCategories.addActionListener(e -> {
SelfCategory selectedSelfCategoryInner = jComboSelfCategories.getItemAt(jComboSelfCategories.getSelectedIndex());
pBySelfCategory.setBackground(model.config.getSelfCategoryColor(selectedSelfCategoryInner));
});
group = new ButtonGroup();
group.add(targetColoring);
group.add(randomColoring);
group.add(groupColoring);
group.add(selfCategoryColoring);
Optional<Color> colorByTargetId = model.config.getColorByTargetId(selectedTargetIdOuter);
pPedestrian.setBackground(colorByTargetId.orElseGet(() -> model.config.getPedestrianDefaultColor()));
pPedestrian.setPreferredSize(new Dimension(130, 20));
pByTargetId.setBackground(colorByTargetId.orElseGet(() -> model.config.getPedestrianDefaultColor()));
pByTargetId.setPreferredSize(new Dimension(130, 20));
// When user changes a color, save it in the model.
bChange.addActionListener(new ActionSetPedestrianColor("Set Pedestrian Color", model, pPedestrian,
bChangeTargetColor.addActionListener(new ActionSetPedestrianColor("Set Pedestrian Color", model, pByTargetId,
jComboTargetIds));
// Retrieve configured color from "model" or use default color.
......@@ -218,10 +248,9 @@ public class SettingsDialog extends JDialog {
}
Optional<Color> colorByTarget = config.getColorByTargetId(selectedTargetIdInner);
pPedestrian.setBackground(colorByTarget.orElseGet(() -> model.config.getPedestrianDefaultColor()));
pByTargetId.setBackground(colorByTarget.orElseGet(() -> model.config.getPedestrianDefaultColor()));
});
final JButton bPedestrianNoTarget = new JButton(Messages.getString("SettingsDialog.btnEditColor.text"));
final JPanel pPedestrianNoTarget = new JPanel();
Optional<Color> notTargetPedCol = config.getColorByTargetId((-1));
......@@ -233,21 +262,27 @@ public class SettingsDialog extends JDialog {
int row = 0;
int column = 2;
// Bene's "Criteria Coloring" comes in the next row.
row += NEXT_CELL;
colorSettingsPane.add(targetColoring, cc.xy(2, 2));
colorSettingsPane.add(jComboTargetIds, cc.xy(4, 2));
colorSettingsPane.add(pPedestrian, cc.xy(6, 2));
colorSettingsPane.add(bChange, cc.xy(8, 2));
colorSettingsPane.add(pByTargetId, cc.xy(6, 2));
colorSettingsPane.add(bChangeTargetColor, cc.xy(8, 2));
colorSettingsPane.add(new JLabel(Messages.getString("SettingsDialog.lblPedestrianNoTarget.text") + ":"), cc.xy(4, 4));
colorSettingsPane.add(pPedestrianNoTarget, cc.xy(6, 4));
colorSettingsPane.add(bPedestrianNoTarget, cc.xy(8, 4));
colorSettingsPane.add(randomColoring, cc.xyw(2, 6, 9));
colorSettingsPane.add(groupColoring, cc.xyw(2, 8, 9));
row = 10;
colorSettingsPane.add(selfCategoryColoring, cc.xy(2, row));
colorSettingsPane.add(jComboSelfCategories, cc.xy(4, row));
colorSettingsPane.add(pBySelfCategory, cc.xy(6, row));
colorSettingsPane.add(bChangeSelfCategoryColor, cc.xy(8, row));
// Evacuation time and criteria coloring comes in the next row see "postvisualization/.../SettingsDialog.java"
}
private void createColorCanvasesAndChangeButtonsOnPane(JLayeredPane colorSettingsPane) {
......@@ -326,6 +361,12 @@ public class SettingsDialog extends JDialog {
return comboBox;
}
private JComboBox<SelfCategory> createSelfCategoriesComboBox() {
JComboBox<SelfCategory> comboBox = new JComboBox<>(SelfCategory.values());
return comboBox;
}
private void initOtherSettingsPane(JLayeredPane otherSettingsPane) {
otherSettingsPane.setBorder(
BorderFactory.createTitledBorder(Messages.getString("SettingsDialog.additional.border.text")));
......
......@@ -24,7 +24,7 @@ public class SettingsDialog extends org.vadere.gui.components.view.SettingsDialo
super.initComponents();
CellConstraints cc = new CellConstraints();
JRadioButton chShowEvacTimeColor = new JRadioButton(Messages.getString("PostVis.chShowEvacTimeColor.text"));
agentColorSettingsPane.add(chShowEvacTimeColor, cc.xyw(2, 10, 9));
agentColorSettingsPane.add(chShowEvacTimeColor, cc.xyw(2, 12, 9));
chShowEvacTimeColor.addItemListener(e -> {
model.setAgentColoring(AgentColoring.EVACUATION_TIMES);
model.notifyObservers();
......@@ -33,8 +33,8 @@ public class SettingsDialog extends org.vadere.gui.components.view.SettingsDialo
JRadioButton chShowCriteriaColor = new JRadioButton(Messages.getString("PostVis.chShowCriteriaColor.text") + ":");
PedestrianColorPanel pedestrianColorPanel = new PedestrianColorPanel(model);
agentColorSettingsPane.add(chShowCriteriaColor, cc.xy(2, 12, CellConstraints.LEFT, CellConstraints.TOP));
agentColorSettingsPane.add(pedestrianColorPanel, cc.xyw(4, 12, 7));
agentColorSettingsPane.add(chShowCriteriaColor, cc.xy(2, 14, CellConstraints.LEFT, CellConstraints.TOP));
agentColorSettingsPane.add(pedestrianColorPanel, cc.xyw(4, 14, 7));
chShowCriteriaColor.addItemListener(e -> {
model.setAgentColoring(AgentColoring.PREDICATE);
model.notifyObservers();
......
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