// Path: game-tools/src/main/java/com/game/tools/mapeditor/SpriteMap.java
// public class SpriteMap implements Iterable<Image> {
// 
// 	public final int elementWidth;
// 	public final int elementHeight;
// 	protected final List<Image> sprites;
// 
// 	public SpriteMap(int elementWidth, int elementHeight) {
// 		this.elementWidth = elementWidth;
// 		this.elementHeight = elementHeight;
// 
// 		sprites = new ArrayList<Image>();
// 	}
// 
// 	public SpriteMap(URL resource, int elementWidth, int elementHeight) throws IOException {
// 		this (elementWidth, elementHeight);
// 
// 		BufferedImage image = ImageIO.read(resource);
// 
// 		if (image.getWidth() % elementWidth != 0 || image.getHeight() % elementHeight != 0) {
// 			// fatal error
// 			throw new RuntimeException("Attempted to load sprite map, but the image dimensions aren't multiples of the element dimensions.");
// 		}
// 
// 		int width = image.getWidth() / elementWidth;
// 		int height = image.getHeight() / elementHeight;
// 
// 		for (int y = 0;y < height;y++) {
// 			for (int x = 0;x < width;x++) {
// 				Image sprite = image.getSubimage(x * elementWidth, y * elementHeight, elementWidth, elementHeight);
// 				this.add(sprite);
// 			}
// 		}
// 	}
// 
// 	public void add(Image sprite) {
// 		sprites.add(sprite);
// 	}
// 
// 	public Image get(int index) {
// 		return sprites.get(index);
// 	}
// 
// 	public BufferedImage generateImage() {
// 		return null; // generate 1 image with all the sprites tiled
// 	}
// 
// 	@Override
// 	public Iterator<Image> iterator() {
// 		return sprites.iterator();
// 	}
// }


import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Image;
import java.awt.image.BufferedImage;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListCellRenderer;
import javax.swing.SwingConstants;
import javax.swing.UIManager;
import com.game.tools.mapeditor.SpriteMap;
package com.game.tools.mapeditor.ui;




@SuppressWarnings("serial")
public class SpriteBox extends JComboBox {

	protected static class SpriteBoxRenderer extends JLabel implements ListCellRenderer {
		protected final SpriteBox box;

		public SpriteBoxRenderer(SpriteBox box) {
			this.box = box;

			super.setBackground(Color.BLACK);
			super.setOpaque(true);
			super.setHorizontalAlignment(SwingConstants.CENTER);
			super.setVerticalAlignment(SwingConstants.CENTER);
		}

		@Override
		public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
			super.setIcon((ImageIcon) value);
			super.setBorder(isSelected ? BorderFactory.createLineBorder(Color.RED) : null);

			return this;
		}
	}

	// Width needs to account for the scrollbar/dropdown arrow
// Path: game-tools/src/main/java/com/game/tools/mapeditor/SpriteMap.java
// public class SpriteMap implements Iterable<Image> {
// 
// 	public final int elementWidth;
// 	public final int elementHeight;
// 	protected final List<Image> sprites;
// 
// 	public SpriteMap(int elementWidth, int elementHeight) {
// 		this.elementWidth = elementWidth;
// 		this.elementHeight = elementHeight;
// 
// 		sprites = new ArrayList<Image>();
// 	}
// 
// 	public SpriteMap(URL resource, int elementWidth, int elementHeight) throws IOException {
// 		this (elementWidth, elementHeight);
// 
// 		BufferedImage image = ImageIO.read(resource);
// 
// 		if (image.getWidth() % elementWidth != 0 || image.getHeight() % elementHeight != 0) {
// 			// fatal error
// 			throw new RuntimeException("Attempted to load sprite map, but the image dimensions aren't multiples of the element dimensions.");
// 		}
// 
// 		int width = image.getWidth() / elementWidth;
// 		int height = image.getHeight() / elementHeight;
// 
// 		for (int y = 0;y < height;y++) {
// 			for (int x = 0;x < width;x++) {
// 				Image sprite = image.getSubimage(x * elementWidth, y * elementHeight, elementWidth, elementHeight);
// 				this.add(sprite);
// 			}
// 		}
// 	}
// 
// 	public void add(Image sprite) {
// 		sprites.add(sprite);
// 	}
// 
// 	public Image get(int index) {
// 		return sprites.get(index);
// 	}
// 
// 	public BufferedImage generateImage() {
// 		return null; // generate 1 image with all the sprites tiled
// 	}
// 
// 	@Override
// 	public Iterator<Image> iterator() {
// 		return sprites.iterator();
// 	}
// }


// Path: game-tools/src/main/java/com/game/tools/mapeditor/ui/SpriteBox.java
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Image;
import java.awt.image.BufferedImage;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListCellRenderer;
import javax.swing.SwingConstants;
import javax.swing.UIManager;
import com.game.tools.mapeditor.SpriteMap;

package com.game.tools.mapeditor.ui;




@SuppressWarnings("serial")
public class SpriteBox extends JComboBox {

	protected static class SpriteBoxRenderer extends JLabel implements ListCellRenderer {
		protected final SpriteBox box;

		public SpriteBoxRenderer(SpriteBox box) {
			this.box = box;

			super.setBackground(Color.BLACK);
			super.setOpaque(true);
			super.setHorizontalAlignment(SwingConstants.CENTER);
			super.setVerticalAlignment(SwingConstants.CENTER);
		}

		@Override
		public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
			super.setIcon((ImageIcon) value);
			super.setBorder(isSelected ? BorderFactory.createLineBorder(Color.RED) : null);

			return this;
		}
	}

	// Width needs to account for the scrollbar/dropdown arrow
	public SpriteBox(SpriteMap sprites, boolean addBlank) {