de.uni_paderborn.robots.gui
Class ArenaImages

java.lang.Object
  |
  +--de.uni_paderborn.robots.gui.ArenaImages

public class ArenaImages
extends java.lang.Object

Manages the icon sets used for the GUI. For each icon set an instance of this class can be created.


Inner Class Summary
 class ArenaImages.CardImage
          Class for rendering the value number into existing card image
private  class ArenaImages.RobotFilenameFilter
          Class for finding the robot images in a directory
 class ArenaImages.RobotImages
          Datastructure to keep the possible images for robots
 
Field Summary
private  int arenaSize
          the arena size
private  java.awt.Image[] cardColors
          Images for the 4 card values (here used as colors)
private  java.awt.Image[] cardColorsTree
          Images for the 4 card values for the tree.
private  java.util.Hashtable cardImages
          To keep track of card images that already have been created.
private  java.awt.Image emptyImage
          The image for an empty field
private  java.awt.Image exitImage
          The image for an exit
private  int maxHeight
          The maximum height of all the images
private  int maxWidth
          The maximum width of all the images
private  int nextRobotImage
          Image to be used by getNextRobotImage()
private  ArenaImages.RobotImages[] robotImages
          Images available for robots
private  java.awt.Image teleporterImage
          The image for a teleport
private  boolean threeDimensional
          Are the wall of this arena style three dimensional?
private  java.awt.Image[][][][] wall3d
          Images for 3d walls
private  java.awt.Image wallImage
          The image for a 2d wall.
private  java.awt.Image wellImage
          The image for an energy source
 
Constructor Summary
(package private) ArenaImages(java.lang.String directoryName, javax.swing.JFrame frame, int arenaSize)
          Creates a new set of Arena images
 
Method Summary
private  java.awt.Image createImage(java.io.File directory, java.lang.String name, javax.swing.JFrame frame)
          Creates an image in specified directory of specified name.
private  java.awt.Image createImage(java.io.File directory, java.lang.String name, javax.swing.JFrame frame, boolean ignoreMaxSize)
          This is the original method createImage, and now there is the boolean parameter ignoreMaxSize added.
private  void createRobotImages(java.io.File directory, javax.swing.JFrame frame)
          Creates images to be used by the individual robot implementations.
 java.awt.Image getCardImage(int value, int color)
          Get image for card with specified value and color.
 java.awt.Image getCardTreeImage(int value, int color)
          This method does the same as getCardImage, but it generates crads only for the tree, that is in a size of 20.
 java.awt.Image getImageForField(Field field)
          Returns an image matching the item on a field.
 int getMaxHeight()
          Returns the maximum height of all images this object knows
 int getMaxWidth()
          Returns the maximum width of all images this object knows
 ArenaImages.RobotImages getNextRobotImages()
          Returns images for robots.
private  int hasWall(Field field)
          Checks whether the specified field contains a wall.
 boolean is3D()
           
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

threeDimensional

private boolean threeDimensional
Are the wall of this arena style three dimensional? true, if so.

emptyImage

private java.awt.Image emptyImage
The image for an empty field

wallImage

private java.awt.Image wallImage
The image for a 2d wall. If threeDimensional is true, wall3d must be used to get the images.

wellImage

private java.awt.Image wellImage
The image for an energy source

teleporterImage

private java.awt.Image teleporterImage
The image for a teleport

exitImage

private java.awt.Image exitImage
The image for an exit

arenaSize

private int arenaSize
the arena size

maxWidth

private int maxWidth
The maximum width of all the images

maxHeight

private int maxHeight
The maximum height of all the images

wall3d

private java.awt.Image[][][][] wall3d
Images for 3d walls

cardColors

private java.awt.Image[] cardColors
Images for the 4 card values (here used as colors)

cardColorsTree

private java.awt.Image[] cardColorsTree
Images for the 4 card values for the tree. The difference to the normal images: These images do not zoom.

robotImages

private ArenaImages.RobotImages[] robotImages
Images available for robots

nextRobotImage

private int nextRobotImage
Image to be used by getNextRobotImage()

cardImages

private java.util.Hashtable cardImages
To keep track of card images that already have been created.
Constructor Detail

ArenaImages

ArenaImages(java.lang.String directoryName,
            javax.swing.JFrame frame,
            int arenaSize)
Creates a new set of Arena images
Parameters:
directoryName - Name of directory to scan for images
frame - Frame of the application (for getToolkit())
Method Detail

createImage

private java.awt.Image createImage(java.io.File directory,
                                   java.lang.String name,
                                   javax.swing.JFrame frame)
Creates an image in specified directory of specified name. Uses a MediaTracker. This method also keeps track of the maximum dimensions of all images that have been loaded.
Parameters:
directory - Dir in which the image should be
name - file name of image
frame - Frame of the application (for getToolkit())
Returns:
a new created Image

createImage

private java.awt.Image createImage(java.io.File directory,
                                   java.lang.String name,
                                   javax.swing.JFrame frame,
                                   boolean ignoreMaxSize)
This is the original method createImage, and now there is the boolean parameter ignoreMaxSize added. By calling this method with this parameter set false, the method will act like it acted originally, i. e. it verifies if the image is larger than the maxWidth or maxHeight. This verification is useful to draw all images non-cut. But it is not useful, when specifying the statusrobot, which is much larger than any other image. So it was necessary to be able to ignore these size-verifications.

Note:
The original method call with less parameter has been left so it is not necessary to change all code.

Parameters:
directory - Dir in which the image should be
name - file name of image
frame - Frame of the application (for getToolkit())
ignoreMaxSize - true if you want to ignore the size-verification, false otherwise.
Returns:
a new created Image

createRobotImages

private void createRobotImages(java.io.File directory,
                               javax.swing.JFrame frame)
Creates images to be used by the individual robot implementations. This method scans the specified directory for all files beginning with "robot" and loads them as image. Called by constructor ArenaImages()

Parameters:
directory - Directory to be scanned
frame - Frame of the application (for getTollkit())

hasWall

private int hasWall(Field field)
Checks whether the specified field contains a wall. Support method for getImageForField().
Parameters:
field - Field to check
Returns:
1 if there is a wall, 0 otherwise. Not boolean, but int for array support.

getImageForField

public java.awt.Image getImageForField(Field field)
Returns an image matching the item on a field. Supports three-dimensional drawn walls, i.e. it looks at the neighbour fields to determine what image matches these fields.

Parameters:
field - Field to get Image for
Returns:
matching image for field

getNextRobotImages

public ArenaImages.RobotImages getNextRobotImages()
Returns images for robots. Called in sequence, this method returns different robot images. The data structure returned contains references for the possible visual states of the robot (for example west, east, etc.)

Returns:
reference to class RobotImage containing several visual states of the robot image

getMaxWidth

public int getMaxWidth()
Returns the maximum width of all images this object knows
Returns:
the maximum width of all images this object knows

getMaxHeight

public int getMaxHeight()
Returns the maximum height of all images this object knows
Returns:
the maximum height of all images this object knows

getCardImage

public java.awt.Image getCardImage(int value,
                                   int color)
Get image for card with specified value and color. Note that this function renders value as card suite (color) and color as a number on the card, because the card value is number in a fixed domain (1..4) and thus quite suitable for the suite.

Parameters:
value - Card value as defined in Card object
color - Color value as defined in Card object
Returns:
Image for the card or null if value is out of bounds

getCardTreeImage

public java.awt.Image getCardTreeImage(int value,
                                       int color)
This method does the same as getCardImage, but it generates crads only for the tree, that is in a size of 20.

Parameters:
value - Card value as defined in Card object
color - Color value as defined in Card object
Returns:
Image for the card or null if value is out of bounds

is3D

public boolean is3D()