world
Class WorldCreator

java.lang.Object
  |
  +--world.WorldCreator

public class WorldCreator
extends java.lang.Object

A WorldCreator creates a World with particular Background objects whose description and location are given in a specified file, where each line of data is of the following format:

backgroundName xCoordinate yCoordinate width height

where backgroundName is the predetermined name refering to some background (e.g. Vertical-Road, Lake, House)
where xCoordinate refers to the leftmost x-coordinate of the background
where yCoordinate refers to the uppermost y-coordinate of the background
where width refers to the maximum horizontal distance from the xCoordinate of the background object
where height refers to the maximum vertical distance from the yCoordinate of the background object

PLEASE NOTE: This implementation assumes that the file contains no empty lines of data (i.e. the lines of valid data are consecutive); this can be easily modified if desired.


Field Summary
static java.lang.String defaultFilename
          Name of a file to use if a good file name is not supplied as a parameter.
 
Constructor Summary
WorldCreator()
           
 
Method Summary
private static java.io.File getFile()
          [DO include in the starter code] Displays a dialog box to choose the file, if the requested one doesn't exist.
private static java.io.File getFile(java.lang.String requestedFilename)
          Locate the requested file, if possible, or a file selected by the user.
static World modifyWorld(java.lang.String fileName, World w)
          Modifies a currently existing World by adding Background objects specified in the fileName.
static World modifyWorld(World w)
          Modifies a World with Background objects taken from a file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

defaultFilename

public static final java.lang.String defaultFilename
Name of a file to use if a good file name is not supplied as a parameter. Generally the best place to put this file is in the same package (directory) as the class which is processing it; in this case, the same directory as WorldCreator.java.

See Also:
Constant Field Values
Constructor Detail

WorldCreator

public WorldCreator()
Method Detail

modifyWorld

public static World modifyWorld(World w)
Modifies a World with Background objects taken from a file.

Returns:
- World instance of a World object, with the modifed background objects.

modifyWorld

public static World modifyWorld(java.lang.String fileName,
                                World w)
Modifies a currently existing World by adding Background objects specified in the fileName. If the world does not exist (i.e. w is null), a new World is created and returned, in which the Background objects will be added. If the file has bad data, a null World is returned.

Parameters:
fileName - the name of the file describing the background objects; if the fileName is null or empty or if the file cannot be found, a built-in default is tried; if that fails, the user sees a File Chooser dialog and can browse to the desired file.
w - the currently existing World
Returns:
World - instance of a World object if file was read successfully, otherwise null

getFile

private static java.io.File getFile()
[DO include in the starter code] Displays a dialog box to choose the file, if the requested one doesn't exist.

Returns:
the file that the user selected or null if user selected cancel

getFile

private static java.io.File getFile(java.lang.String requestedFilename)
Locate the requested file, if possible, or a file selected by the user. For best results, place the file in the same directory as this class, or in some other package used by the application. Displays a dialog box to choose the file, if the one requested doesn't exist

Returns:
the file that was requested, or one the user selected, or null if user selected cancel