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

Fix #160: In "TikzGenerator.java", use "String.format(Locale.US, ..." to force...

Fix #160: In "TikzGenerator.java", use "String.format(Locale.US, ..." to force a dot as decimal separator.
parent 6c45179a
Pipeline #73292 failed with stages
in 77 minutes and 30 seconds
......@@ -241,7 +241,8 @@ OnlineVis.msgDialogShowPotentialfield.target=Target Potential Field
OnlineVis.msgDialogShowPotentialfield.overall=Potential Field (OSM only)
OnlineVis.msgDialogShowPotentialfield.none=None
TopographyBoundDialog.title = Set Topography Bounds
TopographyBoundDialog.title=Width x Height
TopographyBoundDialog.tooltip=Set topography bounds
InformationDialogError.title=Internal Error
InformationDialogFileError=Could not load file!
......
......@@ -236,7 +236,8 @@ OnlineVis.msgDialogShowPotentialfield.target=Zielpotential
OnlineVis.msgDialogShowPotentialfield.overall=Potential (OSM only)
OnlineVis.msgDialogShowPotentialfield.none=Keines
TopographyBoundDialog.title = Setze Topographie Grenzen
TopographyBoundDialog.title=Breite x H\u00F6he
TopographyBoundDialog.tooltip=Setze Topographie-Gr\u00F6\u00DFe
InformationDialogError.title=Interner Fehelr
InformationDialogFileError=Datei konnte nicht geladen werden!
......
......@@ -81,7 +81,7 @@ public class TikzGenerator {
tikzCode += generateTikzColorDefinitions(model);
tikzCode += convertScenarioElementsToTikz();
String output = (generateCompleteDocument) ? String.format(texTemplate, tikzCode) : tikzCode;
String output = (generateCompleteDocument) ? String.format(Locale.US, texTemplate, tikzCode) : tikzCode;
// TODO: maybe uses Java's resources notation (in general, writing the file should be done by the caller not here).
try {
......@@ -102,19 +102,19 @@ public class TikzGenerator {
String colorTextPattern = "\\definecolor{%s}{RGB}{%d,%d,%d}\n";
Color sourceColor = model.getConfig().getSourceColor();
colorDefinitions += String.format(colorTextPattern, "SourceColor", sourceColor.getRed(), sourceColor.getGreen(), sourceColor.getBlue());
colorDefinitions += String.format(Locale.US, colorTextPattern, "SourceColor", sourceColor.getRed(), sourceColor.getGreen(), sourceColor.getBlue());
Color targetColor = model.getConfig().getTargetColor();
colorDefinitions += String.format(colorTextPattern, "TargetColor", targetColor.getRed(), targetColor.getGreen(), targetColor.getBlue());
colorDefinitions += String.format(Locale.US, colorTextPattern, "TargetColor", targetColor.getRed(), targetColor.getGreen(), targetColor.getBlue());
Color obstacleColor = model.getConfig().getObstacleColor();
colorDefinitions += String.format(colorTextPattern, "ObstacleColor", obstacleColor.getRed(), obstacleColor.getGreen(), obstacleColor.getBlue());
colorDefinitions += String.format(Locale.US, colorTextPattern, "ObstacleColor", obstacleColor.getRed(), obstacleColor.getGreen(), obstacleColor.getBlue());
Color stairColor = model.getConfig().getStairColor();
colorDefinitions += String.format(colorTextPattern, "StairColor", stairColor.getRed(), stairColor.getGreen(), stairColor.getBlue());
colorDefinitions += String.format(Locale.US, colorTextPattern, "StairColor", stairColor.getRed(), stairColor.getGreen(), stairColor.getBlue());
Color agentColor = model.getConfig().getPedestrianDefaultColor();
colorDefinitions += String.format(colorTextPattern, "AgentColor", agentColor.getRed(), agentColor.getGreen(), agentColor.getBlue());
colorDefinitions += String.format(Locale.US, colorTextPattern, "AgentColor", agentColor.getRed(), agentColor.getGreen(), agentColor.getBlue());
return colorDefinitions;
}
......@@ -128,7 +128,7 @@ public class TikzGenerator {
// Clip everything outside of topography bound.
generatedCode += "% Clipping\n";
String clipTextPattern = "\\clip (%f,%f) rectangle (%f,%f);\n";
generatedCode += String.format(clipTextPattern,
generatedCode += String.format(Locale.US, clipTextPattern,
topography.getBounds().x,
topography.getBounds().y,
topography.getBounds().x + topography.getBounds().width,
......@@ -137,7 +137,7 @@ public class TikzGenerator {
// Draw background elements first, then other scenario elements.
generatedCode += "% Ground\n";
String groundTextPattern = (config.isShowGrid()) ? "\\draw[help lines] (%f,%f) grid (%f,%f);\n" : "\\fill[white] (%f,%f) rectangle (%f,%f);\n";
generatedCode += String.format(groundTextPattern,
generatedCode += String.format(Locale.US, groundTextPattern,
topography.getBounds().x,
topography.getBounds().y,
topography.getBounds().x + topography.getBounds().width,
......@@ -146,7 +146,7 @@ public class TikzGenerator {
if (config.isShowSources()) {
generatedCode += "% Sources\n";
for (Source source : topography.getSources()) {
generatedCode += String.format("\\fill[SourceColor] %s;\n", generatePathForScenarioElement(source));
generatedCode += String.format(Locale.US, "\\fill[SourceColor] %s;\n", generatePathForScenarioElement(source));
}
} else {
generatedCode += "% Sources (not enabled in config)\n";
......@@ -155,7 +155,7 @@ public class TikzGenerator {
if (config.isShowTargets()) {
generatedCode += "% Targets\n";
for (Target target : topography.getTargets()) {
generatedCode += String.format("\\fill[TargetColor] %s;\n", generatePathForScenarioElement(target));
generatedCode += String.format(Locale.US, "\\fill[TargetColor] %s;\n", generatePathForScenarioElement(target));
}
} else {
generatedCode += "% Targets (not enabled in config)\n";
......@@ -164,7 +164,7 @@ public class TikzGenerator {
if (config.isShowObstacles()) {
generatedCode += "% Obstacles\n";
for (Obstacle obstacle : topography.getObstacles()) {
generatedCode += String.format("\\fill[ObstacleColor] %s;\n", generatePathForScenarioElement(obstacle));
generatedCode += String.format(Locale.US, "\\fill[ObstacleColor] %s;\n", generatePathForScenarioElement(obstacle));
}
} else {
generatedCode += "% Obstacles (not enabled in config)\n";
......@@ -173,8 +173,8 @@ public class TikzGenerator {
if (config.isShowStairs()) {
generatedCode += "% Stairs\n";
for (Stairs stair : topography.getStairs()) {
generatedCode += String.format("\\fill[black] %s;\n", generatePathForScenarioElement(stair));
generatedCode += String.format("\\fill[StairColor] %s;\n", generatePathForStairs(stair));
generatedCode += String.format(Locale.US, "\\fill[black] %s;\n", generatePathForScenarioElement(stair));
generatedCode += String.format(Locale.US, "\\fill[StairColor] %s;\n", generatePathForStairs(stair));
}
} else {
generatedCode += "% Stairs (not enabled in config)\n";
......@@ -186,7 +186,7 @@ public class TikzGenerator {
if (model instanceof PostvisualizationModel) {
generatedCode += drawTrajectories((PostvisualizationModel)model);
} else {
generatedCode += String.format("%% Passed model %s does not contain trajectories\n", model.getClass().getSimpleName());
generatedCode += String.format(Locale.US, "%% Passed model %s does not contain trajectories\n", model.getClass().getSimpleName());
}
} else {
generatedCode += "% Trajectories (not enabled in config)\n";
......@@ -215,7 +215,7 @@ public class TikzGenerator {
// Use a newline ("to\n") for joining because TeX could possibly choke up on long lines.
String trajectoryAsTikzString = trajectoryPoints
.map(point -> String.format("(%f,%f)", point.x, point.y))
.map(point -> String.format(Locale.US, "(%f,%f)", point.x, point.y))
.collect(Collectors.joining(" to\n"));
String coloredTrajectory = applyAgentColorToTrajectory(trajectoryAsTikzString, trajectory.getAgent(currentTimeStep));
......@@ -225,7 +225,7 @@ public class TikzGenerator {
String trajectoryEndStepAsString = (trajectoryEndStep.isPresent()) ? "" + trajectoryEndStep.get().toString() : "unknown end step" ;
String currentTimeStepAsString = currentTimeStep.toString();
generatedCode.append(String.format("%% Trajectory Agent %d @ step %s of %s\n", pedestrianId, currentTimeStepAsString, trajectoryEndStepAsString));
generatedCode.append(String.format(Locale.US, "%% Trajectory Agent %d @ step %s of %s\n", pedestrianId, currentTimeStepAsString, trajectoryEndStepAsString));
generatedCode.append(coloredTrajectory);
});
}
......@@ -247,10 +247,10 @@ public class TikzGenerator {
pedestrianColor = renderer.getPedestrianColor(pedestrian);
}
colorString = String.format("{rgb,255: red,%d; green,%d; blue,%d}", pedestrianColor.getRed(), pedestrianColor.getGreen(), pedestrianColor.getBlue());
colorString = String.format(Locale.US, "{rgb,255: red,%d; green,%d; blue,%d}", pedestrianColor.getRed(), pedestrianColor.getGreen(), pedestrianColor.getBlue());
}
return String.format("\\draw[draw=%s]\n%s;\n", colorString, trajectory);
return String.format(Locale.US, "\\draw[draw=%s]\n%s;\n", colorString, trajectory);
}
@NotNull
......@@ -265,29 +265,29 @@ public class TikzGenerator {
Color pedestrianColor = renderer.getAgentRender().getGroupColor(pedestrian);
Shape pedestrianShape = renderer.getAgentRender().getShape(pedestrian);
String colorString = String.format("{rgb,255: red,%d; green,%d; blue,%d}", pedestrianColor.getRed(), pedestrianColor.getGreen(), pedestrianColor.getBlue());
generatedCode += String.format("\\fill[fill=%s] %s;\n", colorString, generatePathForShape(pedestrianShape));
String colorString = String.format(Locale.US, "{rgb,255: red,%d; green,%d; blue,%d}", pedestrianColor.getRed(), pedestrianColor.getGreen(), pedestrianColor.getBlue());
generatedCode += String.format(Locale.US, "\\fill[fill=%s] %s;\n", colorString, generatePathForShape(pedestrianShape));
} catch (ClassCastException cce) {
logger.error("Error casting to Pedestrian");
cce.printStackTrace();
// Fall back to default rendering of agents.
String agentTextPattern = "\\fill[AgentColor] (%f,%f) circle [radius=%fcm];\n";
generatedCode += String.format(agentTextPattern, agent.getPosition().x, agent.getPosition().y, agent.getRadius());
generatedCode += String.format(Locale.US, agentTextPattern, agent.getPosition().x, agent.getPosition().y, agent.getRadius());
}
} else {
Pedestrian pedestrian = (Pedestrian) agent;
Color pedestrianColor = renderer.getPedestrianColor(pedestrian);
String colorString = String.format("{rgb,255: red,%d; green,%d; blue,%d}", pedestrianColor.getRed(), pedestrianColor.getGreen(), pedestrianColor.getBlue());
String colorString = String.format(Locale.US, "{rgb,255: red,%d; green,%d; blue,%d}", pedestrianColor.getRed(), pedestrianColor.getGreen(), pedestrianColor.getBlue());
// Do not draw agents as path for performance reasons. Usually, agents have a circular shape.
// generatedCode += String.format("\\fill[AgentColor] %s\n", generatePathForScenarioElement(agent));
// generatedCode += String.format(Locale.US, "\\fill[AgentColor] %s\n", generatePathForScenarioElement(agent));
String agentTextPattern = "\\fill[fill=%s] (%f,%f) circle [radius=%fcm];\n";
generatedCode += String.format(agentTextPattern, colorString, agent.getPosition().x, agent.getPosition().y, agent.getRadius());
generatedCode += String.format(Locale.US, agentTextPattern, colorString, agent.getPosition().x, agent.getPosition().y, agent.getRadius());
}
if (model.isElementSelected() && model.getSelectedElement().equals(agent)) {
String agentTextPattern = "\\draw[magenta] (%f,%f) circle [radius=%fcm];\n";
generatedCode += String.format(agentTextPattern, agent.getPosition().x, agent.getPosition().y, agent.getRadius());
generatedCode += String.format(Locale.US, agentTextPattern, agent.getPosition().x, agent.getPosition().y, agent.getRadius());
}
}
}
......@@ -349,19 +349,19 @@ public class TikzGenerator {
private String convertJavaToTikzPath(int type, float[] coords) {
if (type < SEG_MOVETO || type > SEG_CLOSE) {
throw new IllegalStateException(String.format("Cannot process path segment type: %d (coordinates: %s)", type, Arrays.toString(coords)));
throw new IllegalStateException(String.format(Locale.US, "Cannot process path segment type: %d (coordinates: %s)", type, Arrays.toString(coords)));
}
String convertedPath = translationTable[type];
if (type == SEG_MOVETO) {
convertedPath = String.format(convertedPath, coords[0], coords[1]);
convertedPath = String.format(Locale.US, convertedPath, coords[0], coords[1]);
} else if (type == SEG_LINETO) {
convertedPath = String.format(convertedPath, coords[0], coords[1]);
convertedPath = String.format(Locale.US, convertedPath, coords[0], coords[1]);
} else if (type == SEG_QUADTO) {
convertedPath = String.format(convertedPath, coords[0], coords[1], coords[2], coords[3]);
convertedPath = String.format(Locale.US, convertedPath, coords[0], coords[1], coords[2], coords[3]);
} else if (type == SEG_CUBICTO) {
convertedPath = String.format(convertedPath, coords[0], coords[1], coords[2], coords[3], coords[4], coords[5]);
convertedPath = String.format(Locale.US, convertedPath, coords[0], coords[1], coords[2], coords[3], coords[4], coords[5]);
}
return convertedPath;
......
......@@ -4,6 +4,8 @@ import org.vadere.gui.projectview.view.ProjectView;
import java.awt.*;
import java.awt.geom.Rectangle2D;
import java.util.Locale;
import org.vadere.gui.components.utils.Messages;
import javax.swing.*;
import javax.swing.event.DocumentEvent;
......@@ -20,7 +22,7 @@ public class ActionResizeTopographyBoundDialog {
public ActionResizeTopographyBoundDialog(final Rectangle2D.Double topographyBound){
textField = new JTextField();
textField.setText(String.format("%.3f x %.3f", topographyBound.getWidth(), topographyBound.getHeight()));
textField.setText(String.format(Locale.US, "%.3f x %.3f", topographyBound.getWidth(), topographyBound.getHeight()));
textField.getDocument().addDocumentListener(new DialogListener());
bound = topographyBound;
......@@ -36,7 +38,7 @@ public class ActionResizeTopographyBoundDialog {
return JOptionPane.showConfirmDialog(
ProjectView.getMainWindow(),
textField,
"width x heigt",
Messages.getString("TopographyBoundDialog.title"),
JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION;
}
......
......@@ -304,7 +304,7 @@ public class TopographyWindow extends JPanel {
Resources.class.getResource("/icons/select_shapes_icon.png")), panelModel, undoSupport);
/* resize Topography */
TopographyAction resizeTopographyBound =new ActionResizeTopographyBound("SetTopograpyBound",
TopographyAction resizeTopographyBound = new ActionResizeTopographyBound(Messages.getString("TopographyBoundDialog.tooltip"),
new ImageIcon(Resources.class.getResource("/icons/topography_icon.png")),
panelModel, selectShape, undoSupport);
......
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