/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package com.fourisland.fourpuzzle.window; import com.fourisland.fourpuzzle.Game; import java.awt.Font; import java.awt.FontFormatException; import java.awt.Graphics2D; import java.awt.Rectangle; import java.awt.TexturePaint; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; /** * * @author hatkirby */ public class MessageWindow { private static final int SPACER = 4; private static final int HEIGHT = 4*(new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB).createGraphics().getFontMetrics().getHeight()+SPACER); private List messages; int width; BufferedImage cacheBase; public MessageWindow(String message) { width = Game.WIDTH - Window.Default.getFullWidth(0); messages = new ArrayList(); initalizeMessages(message, new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB).createGraphics()); cacheBase = Window.Default.getImage(width, HEIGHT); } private void initalizeMessages(String message, Graphics2D g) { setFont(g); String temp = message; int len = 0; while (!temp.isEmpty()) { while ((g.getFontMetrics().stringWidth(temp.substring(0, len)) < (width - SPACER)) && (len < temp.length())) { len++; } if (len != temp.length()) { while ((!temp.substring(len, len+1).equals(" ")) && (len > 0)) { len--; } } messages.add(temp.substring(0, len)); if (len != temp.length()) { temp = temp.substring(len+1); } else { temp = ""; } len = 0; } } public void render(Graphics2D g2) { int y = MessageWindowLocation.Bottom.getY(); g2.drawImage(cacheBase, 0, y, null); setFont(g2); int fh = g2.getFontMetrics().getHeight(); int ty = Window.Default.getTopY()+fh-(SPACER/2)+y; int msgs = Math.min(messages.size(), 4); for (int i=0;i