Commit b2cc2ec0 authored by Drahomír Karchňák's avatar Drahomír Karchňák

Added better handling of unknown values in ForumBannerGenerator.

parent dab25bc4
......@@ -22,6 +22,30 @@ public class ForumBannerGenerator extends AbstractImageGenerator {
private Font primaryFont = null;
private Font secondaryFont = null;
private enum UnknownValueMapping {
EN("en", "Unknown"),
CS("cs", "Neznamé"),
DE("de", "Unbekannt");
private static final String FALLBACK = "n/a";
private final String lang;
private final String unknownValue;
UnknownValueMapping(String lang, String unknownValue) {
this.lang = lang;
this.unknownValue = unknownValue;
}
protected static String getUnknownValue(String lang) {
for(UnknownValueMapping item : values()) {
if(item.lang.equals(lang)) return item.unknownValue;
}
return FALLBACK;
}
}
private enum AdditionalValuePositionMapping {
EN("en", 151, 432),
CS("cs", 130, 394),
......@@ -69,13 +93,15 @@ public class ForumBannerGenerator extends AbstractImageGenerator {
renderMainValue(formatNumber(upload, lang), 280, 118, finalImageGraphics);
renderMainValue(formatNumber(ping, lang), 469, 118, finalImageGraphics);
renderAdditionalValue(isp, AdditionalValuePositionMapping.getFirstColumnX(lang), 219, finalImageGraphics);
renderAdditionalValue(typ, AdditionalValuePositionMapping.getFirstColumnX(lang), 254, finalImageGraphics);
renderAdditionalValue(signal, AdditionalValuePositionMapping.getSecondColumnX(lang), 219, finalImageGraphics);
renderAdditionalValue(os, AdditionalValuePositionMapping.getSecondColumnX(lang), 254, finalImageGraphics);
String unknownText = UnknownValueMapping.getUnknownValue(lang);
renderAdditionalValue(isp, unknownText, AdditionalValuePositionMapping.getFirstColumnX(lang), 219, finalImageGraphics);
renderAdditionalValue(typ, unknownText, AdditionalValuePositionMapping.getFirstColumnX(lang), 254, finalImageGraphics);
renderAdditionalValue(signal, unknownText, AdditionalValuePositionMapping.getSecondColumnX(lang), 219, finalImageGraphics);
renderAdditionalValue(os, unknownText, AdditionalValuePositionMapping.getSecondColumnX(lang), 254, finalImageGraphics);
renderTimeDateValue(formattedDate, 550, 16, finalImageGraphics);
renderTimeDateValue(String.format(UTC_FORMAT, formattedTime), 550, 40, finalImageGraphics);
renderTimeDateValue(formattedDate, unknownText, 550, 16, finalImageGraphics);
renderTimeDateValue(String.format(UTC_FORMAT, formattedTime), unknownText, 550, 40, finalImageGraphics);
return finalImage;
}
......@@ -107,8 +133,8 @@ public class ForumBannerGenerator extends AbstractImageGenerator {
graphics.drawString(value, centerX - width/2, centerY + height/2);
}
private void renderAdditionalValue(String value, int posX, int posY, Graphics2D graphics) {
if(value == null || value.isEmpty()) value = "n/a";
private void renderAdditionalValue(String value, String unknownValue, int posX, int posY, Graphics2D graphics) {
if(value == null || value.isEmpty()) value = unknownValue;
graphics.setColor(Color.WHITE);
......@@ -121,8 +147,8 @@ public class ForumBannerGenerator extends AbstractImageGenerator {
graphics.drawString(value, posX, posY + height/2);
}
private void renderTimeDateValue(String value, int posX, int posY, Graphics2D graphics) {
if(value == null || value.isEmpty()) value = "n/a";
private void renderTimeDateValue(String value, String unknownValue, int posX, int posY, Graphics2D graphics) {
if(value == null || value.isEmpty()) value = unknownValue;
graphics.setColor(new Color(22, 47, 103));
......
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