Commit 1677b58d authored by Benedikt Kleinmeier's avatar Benedikt Kleinmeier
Browse files

Moved method "GroupMembership.getColor()" to "DefaultConfig.java"

parent a5486a91
Pipeline #250102 passed with stages
in 144 minutes and 26 seconds
package org.vadere.gui.components.model;
import org.vadere.state.psychology.cognition.GroupMembership;
import java.awt.*;
import java.util.HashMap;
public class DefaultConfig {
// Member Variables
private Color obstacleColor = new Color(0.7f,0.7f,0.7f);
private Color sourceColor = new Color(0.3333333333333333f, 0.6588235294117647f, 0.40784313725490196f);
private Color targetColor = new Color(0.8666666666666667f, 0.51764705882352946f, 0.32156862745098042f);
......@@ -13,72 +18,97 @@ public class DefaultConfig {
private Color pedestrianColor = new Color(0.2980392156862745f, 0.4470588235294118f, 0.7901960784313725f);
private Color measurementAreaColor = Color.RED;
private int measurementAreaAlpha = 140;
private HashMap<GroupMembership, Color> groupMembershipColors = new HashMap<>();
private boolean changed = false;
public DefaultConfig() {}
// Constructors
public DefaultConfig() {
initGroupMembershipColor();
}
public DefaultConfig(final DefaultConfig config) {
this.obstacleColor = config.obstacleColor;
this.sourceColor = config.sourceColor;
this.targetColor = config.targetColor;
this.targetChangerColor = config.targetChangerColor;
this.absorbingAreaColor = config.absorbingAreaColor;
this.densityColor = config.densityColor;
this.obstacleColor = config.obstacleColor;
this.stairColor = config.stairColor;
this.pedestrianColor = config.pedestrianColor;
this.measurementAreaColor = config.measurementAreaColor;
this.measurementAreaAlpha = config.measurementAreaAlpha;
this.stairColor = config.stairColor;
initGroupMembershipColor();
this.changed = config.changed;
}
protected synchronized void setChanged() {
this.changed = true;
/**
* Use this color palette: https://www.color-hex.com/color-palette/38840
* Watch out: The user cannot change these colors currently!
* */
private void initGroupMembershipColor() {
groupMembershipColors.put(GroupMembership.IN_GROUP, new Color(213,94,0));
groupMembershipColors.put(GroupMembership.OUT_GROUP, new Color(0,0,0));
groupMembershipColors.put(GroupMembership.OUT_GROUP_FRIENDLY, new Color(0,135,98));
groupMembershipColors.put(GroupMembership.OUT_GROUP_NEUTRAL, new Color(153,153,153));
groupMembershipColors.put(GroupMembership.OUT_GROUP_HOSTILE, new Color(229,229,0));
}
// Getter
public synchronized boolean hasChanged() {
return changed;
}
public Color getObstacleColor() {
return obstacleColor;
}
public void setObstacleColor(final Color obstacleColor) {
this.obstacleColor = obstacleColor;
setChanged();
public Color getSourceColor() {
return sourceColor;
}
public Color getTargetColor() {
return targetColor;
}
public Color getTargetChangerColor() {
return targetChangerColor;
}
public Color getAbsorbingAreaColor() {
return absorbingAreaColor;
}
public Color getDensityColor() {
return densityColor;
}
public Color getStairColor() {
return stairColor;
}
public void setStairColor(final Color stairColor) {
this.stairColor = stairColor;
setChanged();
public Color getPedestrianColor() {
return pedestrianColor;
}
public Color getMeasurementAreaColor() {
return measurementAreaColor;
}
public void setMeasurementAreaColor(Color measurementAreaColor) {
this.measurementAreaColor = measurementAreaColor;
}
public int getMeasurementAreaAlpha() {
return measurementAreaAlpha;
}
public Color getGroupMembershipColor(GroupMembership groupMembership) {
return groupMembershipColors.get(groupMembership);
}
public void setMeasurementAreaAlpha(int measurementAreaAlpha) {
this.measurementAreaAlpha = measurementAreaAlpha;
// Setter
protected synchronized void setChanged() {
this.changed = true;
}
public Color getSourceColor() {
return sourceColor;
public synchronized void clearChange() {
changed = false;
}
public void setSourceColor(Color sourceColor) {
this.sourceColor = sourceColor;
public void setObstacleColor(final Color obstacleColor) {
this.obstacleColor = obstacleColor;
setChanged();
}
public Color getTargetColor() {
return targetColor;
public void setSourceColor(Color sourceColor) {
this.sourceColor = sourceColor;
setChanged();
}
public void setTargetColor(final Color targetColor) {
......@@ -86,19 +116,11 @@ public class DefaultConfig {
setChanged();
}
public Color getTargetChangerColor() {
return targetChangerColor;
}
public void setTargetChangerColor(final Color targetChangerColor) {
this.targetChangerColor = targetChangerColor;
setChanged();
}
public Color getAbsorbingAreaColor() {
return absorbingAreaColor;
}
public void setAbsorbingAreaColor(final Color absorbingAreaColor) {
this.absorbingAreaColor = absorbingAreaColor;
setChanged();
......@@ -109,23 +131,20 @@ public class DefaultConfig {
setChanged();
}
public Color getPedestrianColor() {
return pedestrianColor;
public void setStairColor(final Color stairColor) {
this.stairColor = stairColor;
setChanged();
}
public void setPedestrianColor(Color pedestrianColor) {
this.pedestrianColor = pedestrianColor;
}
public Color getDensityColor() {
return densityColor;
public void setMeasurementAreaColor(Color measurementAreaColor) {
this.measurementAreaColor = measurementAreaColor;
}
public synchronized boolean hasChanged() {
return changed;
public void setMeasurementAreaAlpha(int measurementAreaAlpha) {
this.measurementAreaAlpha = measurementAreaAlpha;
}
public synchronized void clearChange() {
changed = false;
}
}
......@@ -358,7 +358,7 @@ public abstract class DefaultRenderer {
}
protected void renderPedestrianInOutGroup(final Graphics2D g, Pedestrian pedestrian) {
Color groupMembershipColor = GroupMembership.getColor(pedestrian.getGroupMembership());
Color groupMembershipColor = defaultModel.getConfig().getGroupMembershipColor(pedestrian.getGroupMembership());
g.setColor(groupMembershipColor);
g.setStroke(new BasicStroke(getSelectedShapeBorderLineWidth()));
draw(pedestrian.getShape(), g);
......
......@@ -471,7 +471,7 @@ public class TikzGenerator {
if (model.getConfig().isShowGroups()) {
generatedCode += drawAgentWithGroupSettings(agent);
} else {
generatedCode += drawAgentWithoutGroupStyle(agent);
generatedCode += drawAgentWithoutGroupSettings(agent);
}
}
}
......@@ -502,7 +502,7 @@ public class TikzGenerator {
}
@NotNull
private String drawAgentWithoutGroupStyle(Agent agent) {
private String drawAgentWithoutGroupSettings(Agent agent) {
String generatedCode = "";
// Do not draw agents as path for performance reasons. Usually, agents have a circular shape.
......@@ -540,10 +540,9 @@ public class TikzGenerator {
}
private String getTikzColorString(GroupMembership groupMembership) {
return String.format("{rgb,255: red,%d; green,%d; blue,%d}",
GroupMembership.getColor(groupMembership).getRed(),
GroupMembership.getColor(groupMembership).getGreen(),
GroupMembership.getColor(groupMembership).getBlue());
Color color = model.getConfig().getGroupMembershipColor(groupMembership);
return String.format("{rgb,255: red,%d; green,%d; blue,%d}", color.getRed(), color.getGreen(), color.getBlue());
}
private String generatePathForScenarioElement(ScenarioElement element) {
......
......@@ -45,24 +45,5 @@ public enum GroupMembership {
OUT_GROUP,
OUT_GROUP_FRIENDLY,
OUT_GROUP_NEUTRAL,
OUT_GROUP_HOSTILE;
/** Use this color palette: https://www.color-hex.com/color-palette/38840 */
public static Color getColor(GroupMembership groupMembership) {
Color color = Color.BLACK;
if (groupMembership == IN_GROUP) {
color = new Color(213,94,0);
} else if (groupMembership == OUT_GROUP) {
color = new Color(0,0,0);
} else if (groupMembership == OUT_GROUP_FRIENDLY) {
color = new Color(0,135,98);
} else if (groupMembership == OUT_GROUP_NEUTRAL) {
color = new Color(153,153,153);
} else if (groupMembership == OUT_GROUP_HOSTILE) {
color = new Color(229,229,0);
}
return color;
}
OUT_GROUP_HOSTILE
}
Supports Markdown
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