JTP
Class IO

java.lang.Object
  extended by JTP.IO

public class IO
extends Object

Set of methods for loading levelsets with appropriate the error handling.

Author:
V.Termanis

Field Summary
static int EDITOR_LOAD
          LevelSet will be loaded in editor.
static int EDITOR_NEW
          LevelSet will be created in editor.
static int GAME_LOAD
          LevelSet will be loaded for play.
 
Constructor Summary
IO()
           
 
Method Summary
static boolean editorLoadLevelSet(Editor editor, String filename, JOptionPane op, Screen c, Graphics2D g)
          Tries to load the given file for editing.
static boolean gameLoadLevelSet(GamePlayer gamePlayer, String filename, JOptionPane op, Screen c, int gameMode, Graphics2D g)
          Tries to load the given file for play.
static boolean gameLoadLevelSet(GamePlayer gamePlayer, URL fileURL, JOptionPane op, Screen c, int gameMode, Graphics2D g)
          Tries to load the given file for play.
static String getUserFile(JFileChooser fc, int requestType, String fileExtension, Screen c)
          Prompts user for level set file and returns the absolute path to the chosen file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

GAME_LOAD

public static final int GAME_LOAD
LevelSet will be loaded for play.

See Also:
Constant Field Values

EDITOR_NEW

public static final int EDITOR_NEW
LevelSet will be created in editor.

See Also:
Constant Field Values

EDITOR_LOAD

public static final int EDITOR_LOAD
LevelSet will be loaded in editor.

See Also:
Constant Field Values
Constructor Detail

IO

public IO()
Method Detail

editorLoadLevelSet

public static boolean editorLoadLevelSet(Editor editor,
                                         String filename,
                                         JOptionPane op,
                                         Screen c,
                                         Graphics2D g)
Tries to load the given file for editing.

Parameters:
editor - instance of Editor used for editing.
filename - absolute or relative location of file to load.
op - instance of JOptionPane to use for displaying error messages to the user.
c - parent rendering class (required by JOptionPane).
g - graphics context for updating editor layout.
Returns:
true if the levelset was loaded successfully.

gameLoadLevelSet

public static boolean gameLoadLevelSet(GamePlayer gamePlayer,
                                       String filename,
                                       JOptionPane op,
                                       Screen c,
                                       int gameMode,
                                       Graphics2D g)
Tries to load the given file for play.

Parameters:
gamePlayer - instance of GamePlayer used for playing.
filename - absolute or relative location of file to load.
op - instance of JOptionPane to use for displaying error messages to the user.
c - parent rendering class (required by JOptionPane).
gameMode - type of game to set up. See GamePlayer for possible modes.
g - graphics context for updating in-game layout.
Returns:
true if the levelset was loaded successfully.

gameLoadLevelSet

public static boolean gameLoadLevelSet(GamePlayer gamePlayer,
                                       URL fileURL,
                                       JOptionPane op,
                                       Screen c,
                                       int gameMode,
                                       Graphics2D g)
Tries to load the given file for play. Note: This method can be used to load a set from:

Parameters:
gamePlayer - instance of GamePlayer used for playing.
fileURL - location of file to load.
op - instance of JOptionPane to use for displaying error messages to the user.
c - parent rendering class (required by JOptionPane).
gameMode - type of game to set up. See GamePlayer for possible modes.
g - graphics context for updating in-game layout.
Returns:
true if the levelset was loaded successfully.

getUserFile

public static String getUserFile(JFileChooser fc,
                                 int requestType,
                                 String fileExtension,
                                 Screen c)
                          throws IllegalArgumentException,
                                 NullPointerException
Prompts user for level set file and returns the absolute path to the chosen file. The returned path is guaranteed to end in fileExtension.

Parameters:
fc - instance of JFileChooser for user to select file with.
requestType - one of GAME_LOAD, EDITOR_NEW or EDITOR_LOAD. This dictates the type of error messages shown to the user.
fileExtension - to add to filename, if not already present.
c - parent rendering class (required by JFileChooser).
Returns:
absolute path to chosen file or null.
Throws:
IllegalArgumentException - if requestType is not one of the types specified in this class.
NullPointerException - if any of fc, fileExtension or c are null.