org.haphazard.gui
Class GlobalImageUtilities

java.lang.Object
  extended byorg.haphazard.gui.GlobalImageUtilities

public class GlobalImageUtilities
extends java.lang.Object

A class that handles loading of images and turning them to BufferedImage


Constructor Summary
GlobalImageUtilities()
           
 
Method Summary
static void drawString(java.awt.Graphics2D g, java.awt.Point middleTileScreenCoord, java.lang.String str, java.awt.Color color)
          A static function to draw a string in a graphics context.
 java.awt.image.BufferedImage flipImageHorizontally(java.lang.String entry, java.awt.image.BufferedImage image)
          Flips the imge horizontally and returns the new image
 java.awt.image.BufferedImage flipImageVertically(java.lang.String entry, java.awt.image.BufferedImage image)
          Flips the imge vertically and returns the new image
 java.util.Enumeration getAvailableFlippedHorizontallyImages()
          Gets the available images that has been flipped horizontally
 java.util.Enumeration getAvailableFlippedVerticallyImages()
          Gets the available images that has been flipped vertically
 java.util.Enumeration getAvailableImages()
          Gets the available loaded images
 java.awt.image.BufferedImage getBufferedImage(java.lang.String entry)
          Create Image from a file, then turn that into a BufferedImage.
 java.awt.image.BufferedImage getBufferedImage(java.lang.String entry, int width, int height)
          Create Image from a file, then turn that into a BufferedImage.
static GlobalImageUtilities getInstance()
          Gets an instance of the image utilities
static java.awt.image.BufferedImage getStaticBufferedImage(int width, int height, int type)
           
 void init(javax.swing.JPanel owner)
          Sets the owning drawing area for images
static java.util.Vector line(java.awt.Point p1, java.awt.Point p2)
           
static boolean waitForImage(java.awt.Image image)
          Take an Image associated with a file, and wait until it is done loading.
 boolean waitForImages(java.awt.Image[] images)
          Take some Images associated with files, and wait until they are done loading.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GlobalImageUtilities

public GlobalImageUtilities()
Method Detail

getInstance

public static GlobalImageUtilities getInstance()
Gets an instance of the image utilities

Returns:
An instance of the image utilities

init

public void init(javax.swing.JPanel owner)
Sets the owning drawing area for images

Parameters:
owner - The drawing area of the application

getBufferedImage

public java.awt.image.BufferedImage getBufferedImage(java.lang.String entry)
Create Image from a file, then turn that into a BufferedImage. This function also saves the image in a hashtable. Note: ImageIO makes everything go 5 times slower, creates unoptimized BufferedImage?

Returns:
A loaded image

getBufferedImage

public java.awt.image.BufferedImage getBufferedImage(java.lang.String entry,
                                                     int width,
                                                     int height)
Create Image from a file, then turn that into a BufferedImage. This function also saves the image in a hashtable. Note: ImageIO makes everything go 5 times slower, creates unoptimized BufferedImage?

Returns:
A loaded image

getStaticBufferedImage

public static java.awt.image.BufferedImage getStaticBufferedImage(int width,
                                                                  int height,
                                                                  int type)

flipImageVertically

public java.awt.image.BufferedImage flipImageVertically(java.lang.String entry,
                                                        java.awt.image.BufferedImage image)
Flips the imge vertically and returns the new image

Parameters:
image - the image to be fliped
Returns:
the fliped image

flipImageHorizontally

public java.awt.image.BufferedImage flipImageHorizontally(java.lang.String entry,
                                                          java.awt.image.BufferedImage image)
Flips the imge horizontally and returns the new image

Parameters:
image - the image to be fliped
Returns:
the fliped image

waitForImage

public static boolean waitForImage(java.awt.Image image)
Take an Image associated with a file, and wait until it is done loading. Just a simple application of MediaTracker. If you are loading multiple images, don't use this consecutive times; instead use the version that takes an array of images.

Parameters:
image - The image to wait on
Returns:
True if the load succeeded

waitForImages

public boolean waitForImages(java.awt.Image[] images)
Take some Images associated with files, and wait until they are done loading. Just a simple application of MediaTracker.

Parameters:
images - The images to wait on
Returns:
True if succeeded

getAvailableImages

public java.util.Enumeration getAvailableImages()
Gets the available loaded images

Returns:
An enumeration of the images paths

getAvailableFlippedVerticallyImages

public java.util.Enumeration getAvailableFlippedVerticallyImages()
Gets the available images that has been flipped vertically

Returns:
An enumeration of the images paths

getAvailableFlippedHorizontallyImages

public java.util.Enumeration getAvailableFlippedHorizontallyImages()
Gets the available images that has been flipped horizontally

Returns:
An enumeration of the images paths

line

public static java.util.Vector line(java.awt.Point p1,
                                    java.awt.Point p2)

drawString

public static void drawString(java.awt.Graphics2D g,
                              java.awt.Point middleTileScreenCoord,
                              java.lang.String str,
                              java.awt.Color color)
A static function to draw a string in a graphics context.

Parameters:
g - the Graphics2D context
middleTileScreenCoord - the coordinate on the screen where the middle of the string should be
str - the string to be drawn
color - the color of the string