package main.java.gui.board;

import java.awt.Graphics2D;
import java.awt.geom.AffineTransform;
import java.awt.image.AffineTransformOp;
import java.awt.image.BufferedImage;
import java.util.Hashtable;

import main.java.data.Tile;
import main.java.gui.util.Resources;

public class TileImage {

	// Private
	
	static private Hashtable<String, BufferedImage> tilesHashTable = null;
	
	static {
		tilesHashTable = new Hashtable<String, BufferedImage>();
	}
	
	// Public
	
	public static BufferedImage getImage(Tile tile) {
		String tileID = tile.getTileID();
		BufferedImage tileImage = null;
		
		tileImage = tilesHashTable.get(tileID);
		if (tileImage != null) {
			return tileImage;
		}
		
		tileImage = Resources.imageNamed(tileID);
		if (tileImage != null) { 
			tilesHashTable.put(tileID, tileImage);
			return tileImage;
		}
		
		return tileImage;
	}
	
	public static BufferedImage getRotatedImage(Tile tile) {
		BufferedImage image = TileImage.getImage(tile);
		
		AffineTransform at = new AffineTransform();
		at.translate(image.getWidth() / 2, image.getHeight() / 2);
		at.rotate(Math.toRadians(tile.getTileDirection().getVal()*90));
		at.translate(-image.getWidth() / 2, -image.getHeight() / 2);
		
		AffineTransformOp op = new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR);
	    return op.filter(image, null);
	}
	
	public static void drawTile(Graphics2D g2d, Tile tile, int x, int y, int width) {
		BufferedImage image = TileImage.getImage(tile);
		
		AffineTransform at = new AffineTransform();
		at.translate(x + width / 2, y + width / 2);
		at.rotate(Math.toRadians(tile.getTileDirection().getVal()*90));
		at.scale((double)width / (double)image.getWidth(),
				 (double)width / (double)image.getHeight());
		at.translate(-image.getWidth() / 2, -image.getHeight() / 2);
		
		g2d.drawImage(image, at, null);
	}
	
}

@@ -23,16 +23,39 @@
 board;%0A%0A
+import java.awt.Color;%0A
 import j
@@ -1809,19 +1809,16 @@
 ) / 2);%0A
-%09%09%0A
 %09%09g2d.dr
@@ -1839,19 +1839,179 @@
  at, null);%0A
+%09%09%0A%09%09if (tile.isStop()) %7B%0A%09%09%09System.out.println(%22IS STOP !!!!!!!!!!!!!!!!!!!!%22);%0A%09%09%09g2d.setColor(Color.RED);%0A%09%09%09g2d.fillRect(width/2-5, width/2-5, 10, 10);%0A%09%09%7D%0A
 %09%7D%0A%09%0A%7D%0A

Add stop to tile image