* @param description
* @param category
* @return the drawn sprite
*/
public Sprite createAchievementBox(String title, String description, String category) {
final GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
// Get the category image
// initialize category image with empty image in case loading the image fails
BufferedImage categoryImage = gc.createCompatibleImage(32, 32, Transparency.BITMASK);
String imageName = ACHIEVEMENT_IMAGE_FOLDER + category.toLowerCase(Locale.ENGLISH) + ".png";
try {
categoryImage = ImageIO.read(AchievementBoxFactory.class.getClassLoader().getResourceAsStream(imageName));
} catch (IOException e) {
Logger.getLogger(AchievementBoxFactory.class).error("Error loading achievement box image: " + imageName, e);
}
// Calculate size for the message box
String fontName = WtWindowManager.getInstance().getProperty("ui.logfont", FONT_NAME);
Font font = new Font(fontName, Font.PLAIN, 14);
Font largeFont = font.deriveFont(20f);
Rectangle2D titleRect = largeFont.getStringBounds(title, graphics.getFontRenderContext());
Rectangle2D textRect = font.getStringBounds(description, graphics.getFontRenderContext());
int width = (int) Math.max(titleRect.getWidth(), textRect.getWidth())+categoryImage.getWidth();
int height = (int) Math.max(categoryImage.getHeight(), (titleRect.getHeight() + textRect.getHeight()));
width += 2 * SIDE_MARGIN + IMAGE_PAD;
height += TOP_MARGIN + BOTTOM_MARGIN;
// Create the background sprite
final BufferedImage image = gc.createCompatibleImage(width, height, Transparency.BITMASK);
final Graphics2D g2d = image.createGraphics();
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2d.setComposite(AlphaComposite.Src);
BackgroundPainter bp = new BackgroundPainter(BACKGROUND);
bp.paint(g2d, width, height);