Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.newdawn.slick.tools.packulike;
  
  import java.awt.Color;
  import java.awt.Dimension;
  import java.awt.Graphics;
  import java.awt.Image;
  import java.awt.Rectangle;
 
The panel displaying the currently generated sprite sheet

Author(s):
kevin
 
 public class SheetPanel extends JPanel {
The image currently generated
 
 	private Image image;
The background paint to show transparency
 
 	private TexturePaint background;
The width of the image
 
 	private int width;
The height of the image
 
 	private int height;
The sheet that has been generated
 
 	private Sheet sheet;
The packer tool this panel is part of
 
 	private Packer packer;
The list of selected sprites
 
 	private ArrayList selected = new ArrayList();

Create a panel showing a sprite sheet

Parameters:
p The GUI tool this panel is part of
 
 	public SheetPanel(Packer p) {
 		this. = p;
 		
 		Color base = .;
 		BufferedImage image = new BufferedImage(50, 50,
 		Graphics2D g = (Graphics2Dimage.getGraphics();
 		g.setColor(base);
 		g.fillRect(0, 0, image.getWidth(), image.getHeight());
 		g.setColor(base.darker());
 		g.fillRect(image.getWidth() / 2, 0, image.getWidth() / 2, image
 				.getHeight() / 2);
 		g.fillRect(0, image.getHeight() / 2, image.getWidth() / 2, image
 				.getHeight() / 2);
 
 		 = new TexturePaint(imagenew Rectangle(0, 0, image
 				.getWidth(), image.getHeight()));
 		
 			public void mousePressed(MouseEvent e) {
 				Sprite sprite = .getSpriteAt(e.getX(), e.getY());
 				
 				if (sprite != null) {
 					ArrayList selection = new ArrayList();
 					if ((e.getModifiersEx() & .) != 0) {
 						selection.addAll();
 					}
 					selection.add(sprite);
 					
 					.select(selection);
 				}
 			}
 		});
 	}

Set the list of selected sprites

Parameters:
sprites THe list of selected sprites
 
 	public void setSelection(ArrayList sprites) {
 		this. = sprites;
 		repaint(0);
 	}

Set the size of the sprite sheet

Parameters:
width The width of the sheet
height The height of the sheet
 
 	public void setTextureSize(int widthint height) {
 		setPreferredSize(new Dimension(widthheight));
 		setSize(new Dimension(widthheight));
 		this. = width;
 		this. = height;
 	}

Set the image to be displayed (the sprite sheet)

Parameters:
sheet The sheet to be displayed
	public void setImage(Sheet sheet) {
		this. = sheet;
		this. = sheet.getImage();
	}

	public void paint(Graphics g1d) {
        Graphics2D g = (Graphics2Dg1d;
        
		if ( != null) {
			g.drawImage(, 0, 0, null);
		}
		for (int i=0;i<.size();i++) {
			Sprite sprite = (Sprite.get(i);
			g.drawRect(sprite.getX(), sprite.getY(), sprite.getWidth(), sprite.getHeight());
		}
	}
New to GrepCode? Check out our FAQ X