jdalbey

GridImages skeleton

Jan 27th, 2014
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.34 KB | None | 0 0
  1.  
  2. import java.util.HashMap;
  3. import javax.swing.ImageIcon;
  4. import java.awt.image.*;
  5. import java.awt.*;
  6. import java.io.*;
  7. import java.util.List;
  8. import java.net.URL;
  9. import javax.imageio.ImageIO;
  10. import javax.swing.GrayFilter;
  11.  
  12. /**
  13.  * GridImages represents the images to be used for pieces and backgrounds in
  14.  * a grid game.  GridImages acts like a map between piece names and their
  15.  * corresponding images.  The key values do NOT contain actual filenames.
  16.  * In most cases the plugin author will want to use an enum name as the key.
  17.  *
  18.  * GridImages is a Singleton.
  19.  */
  20. public final class GridImages
  21. {
  22.     /** The name of the directory containing the images */
  23.     public final static String kImageDir = "Images";
  24.     /** The prefix for background images */
  25.     public final static String kBackgroundPrefix = "background";
  26.     /** The prefix for piece images */
  27.     public final static String kPiecePrefix = "piece";
  28.     /** The prefixes for all desired files to be loaded. */
  29.     public final static String[] kImagePrefixes =
  30.     {
  31.         kBackgroundPrefix, kPiecePrefix
  32.     };
  33.     private final String imagePath = kImageDir + System.getProperty(
  34.             "file.separator");
  35.  
  36.     /** Initialize and return the one allowed instance of this class.
  37.      * The instance contains images loaded from <code>kImageDir</code>,
  38.      * whose names begin with the <code>kImagePrefixes</code>.  For example,
  39.      * if <code>kPiecePrefix</code> contains "piece" then all images whose filenames
  40.      * begin with "piece" will be loaded from <code>kImageDir</code>:
  41.      * piecehidden.jpg, pieceflagged.png, pieceflower.jpg and so on.
  42.      *
  43.      * @param gamePrefix is the folder in which to find <code>kImageDir</code>
  44.      * @return an instance of this class.
  45.      * @post An error message will be displayed if there are no files with
  46.      * the given prefix in the specified directory.  Hint: use FilenameFilter.
  47.      */
  48.     public static GridImages createInstance(String gamePrefix)
  49.  
  50.     /** Retrieve an image.
  51.      * @param name the name of the desired image (usually the <code>name()</code>
  52.      * of a piece enum)
  53.      * @return ImageIcon the image associated with the specified name
  54.      */
  55.     public ImageIcon getImage(String name)
  56.  
  57.     /** Constructor is private to defeat instantiation */
  58.     private GridImages(String prefix)
  59.  
  60. }
Advertisement
Add Comment
Please, Sign In to add comment