JTP
Class Editor

java.lang.Object
  extended by JTP.Editor

public class Editor
extends Object

Defines function and rendering of the editor component.

Author:
V.Termanis

Field Summary
static int ARROW_DOWN
           
static int ARROW_LEFT
           
static int ARROW_RIGHT
           
static int ARROW_UP
           
static int CLOSE
           
static int GRAVITY
           
static int GRID
           
static int ICE
           
static int LEVEL_BACK
           
static int LEVEL_CLEAR
           
static int LEVEL_FIRST
           
static int LEVEL_FORWARD
           
static int LEVEL_LAST
           
static int LEVEL_MESSAGES
           
static int LEVEL_PLAY
           
static int LEVEL_SWAP
           
static int LEVEL_TIME
           
static int NONE
           
static int NORMAL
           
static int SAVE
           
static int SAVECLOSE
           
static int START
           
static int START2
           
static int TELEPORT
           
 
Constructor Summary
Editor(Images imgData, ScreenFrames frames, TilePainter tPainter, int gridSize, int tileHeightLimit, int buttonSpacing, float buttonBorderThickness, Color buttonBorderColor, Font txtFont, Color gridColor, Color gridHighlight, Color txtColor, Graphics2D g, String fileExtension, String levelSetFilename)
          Creates a new Editor instance with the specified parameters.
 
Method Summary
 int clickResult(int button, Component screen)
          Handles mouse (up) events based on last mouse location from last updateUI call.
 boolean cursorChange()
          Indicates whether the cursor should be change (e.g.
 boolean cursorChange(boolean exit)
          Indicates whether the cursor should be change (e.g.
 void drawAll(Graphics2D g)
          Draws all editor components and grid.
 void drawClickUpdate(Graphics2D g)
          Draws update after mouse click (call after clickResult)
 void drawKeyUpdate(Graphics2D g)
          Draws update required after keypress (call after keyUpdate)
 void drawUpdate(Graphics2D g)
          Draw any required changes after mouse movement (call after updateUI
 LevelSet getTestSet()
          Returns levelset for testing (so can be loaded into GamePlayer .
 int keyResult(int keyCode, Component screen)
          Processes a keypress.
 void loadLevelSet(String filename, Component c, Graphics2D g)
          Loads a levelset from disk or creates a new one if it does not exist.
 boolean mousePressed(int button)
          Handles mouse (down) events.
 boolean redrawWanted()
          Indicates whether screen should be refreshed.
 Rectangle updateUI(Point mouseLocation)
          Determines whether a different button or tile is active and returns clipping area (for drawing) is so.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NONE

public static final int NONE
See Also:
Constant Field Values

NORMAL

public static final int NORMAL
See Also:
Constant Field Values

ICE

public static final int ICE
See Also:
Constant Field Values

TELEPORT

public static final int TELEPORT
See Also:
Constant Field Values

GRAVITY

public static final int GRAVITY
See Also:
Constant Field Values

ARROW_UP

public static final int ARROW_UP
See Also:
Constant Field Values

ARROW_DOWN

public static final int ARROW_DOWN
See Also:
Constant Field Values

ARROW_LEFT

public static final int ARROW_LEFT
See Also:
Constant Field Values

ARROW_RIGHT

public static final int ARROW_RIGHT
See Also:
Constant Field Values

START

public static final int START
See Also:
Constant Field Values

START2

public static final int START2
See Also:
Constant Field Values

LEVEL_SWAP

public static final int LEVEL_SWAP
See Also:
Constant Field Values

LEVEL_FIRST

public static final int LEVEL_FIRST
See Also:
Constant Field Values

LEVEL_LAST

public static final int LEVEL_LAST
See Also:
Constant Field Values

LEVEL_MESSAGES

public static final int LEVEL_MESSAGES
See Also:
Constant Field Values

LEVEL_BACK

public static final int LEVEL_BACK
See Also:
Constant Field Values

LEVEL_FORWARD

public static final int LEVEL_FORWARD
See Also:
Constant Field Values

LEVEL_TIME

public static final int LEVEL_TIME
See Also:
Constant Field Values

LEVEL_CLEAR

public static final int LEVEL_CLEAR
See Also:
Constant Field Values

LEVEL_PLAY

public static final int LEVEL_PLAY
See Also:
Constant Field Values

SAVE

public static final int SAVE
See Also:
Constant Field Values

CLOSE

public static final int CLOSE
See Also:
Constant Field Values

SAVECLOSE

public static final int SAVECLOSE
See Also:
Constant Field Values

GRID

public static final int GRID
See Also:
Constant Field Values
Constructor Detail

Editor

public Editor(Images imgData,
              ScreenFrames frames,
              TilePainter tPainter,
              int gridSize,
              int tileHeightLimit,
              int buttonSpacing,
              float buttonBorderThickness,
              Color buttonBorderColor,
              Font txtFont,
              Color gridColor,
              Color gridHighlight,
              Color txtColor,
              Graphics2D g,
              String fileExtension,
              String levelSetFilename)
       throws IOException
Creates a new Editor instance with the specified parameters.

Parameters:
imgData - access to global image resources
frames - responsible for background and frame painting
tPainter - responsible for drawing grid and tiles
gridSize - width and height of grid (e.g. 15x15)
tileHeightLimit - maximum height a pile can have
buttonSpacing - horizontal and vertical spacing inbetween buttons
buttonBorderThickness - thickness of highlighted button border
buttonBorderColor - colour of highlighted button border
txtFont - style of all text (except tile numbers)
gridColor - colour of grid drawn underneath tiles
gridHighlight - colour of highlighted grid position
txtColor - colour of all text (except tile numbers)
g - graphics context for rendering
fileExtension - so upon new levelset creation the correct extension is added if required
levelSetFilename - a levelset to load initially, can be null
Throws:
IOException - if the specified levelset cannot be loaded/created
Method Detail

loadLevelSet

public void loadLevelSet(String filename,
                         Component c,
                         Graphics2D g)
                  throws IOException
Loads a levelset from disk or creates a new one if it does not exist.

Parameters:
filename - absolute path for new/existing levelset
c - parent component for drawing dialogs if required
g - graphics context for rendering
Throws:
IOException - if either the levelset could not be loaded or a new one could not be created.

clickResult

public int clickResult(int button,
                       Component screen)
Handles mouse (up) events based on last mouse location from last updateUI call.

Parameters:
button - the mouse button which was released
screen - parent component so can draw dialogs if required
Returns:
the performed function or NONE

mousePressed

public boolean mousePressed(int button)
Handles mouse (down) events.

Parameters:
button - which button has been pressed (down)
Returns:
true if a screen update is now required.

keyResult

public int keyResult(int keyCode,
                     Component screen)
Processes a keypress.

Parameters:
keyCode - one of the codes as defined in the KeyEvent class.
screen - requires parent component so can draw dialogs if required
Returns:
the performed action or NONE

updateUI

public Rectangle updateUI(Point mouseLocation)
Determines whether a different button or tile is active and returns clipping area (for drawing) is so.

Parameters:
mouseLocation - current mouse position
Returns:
the clipping rectangle or null if no screen update is required.

redrawWanted

public boolean redrawWanted()
Indicates whether screen should be refreshed. Note: This might say the screen should be refreshed even though a call to updateUI returned nothing.

Returns:
true if screen should be redrawn

drawUpdate

public void drawUpdate(Graphics2D g)
Draw any required changes after mouse movement (call after updateUI

Parameters:
g - graphics context used for rendering

drawClickUpdate

public void drawClickUpdate(Graphics2D g)
Draws update after mouse click (call after clickResult)

Parameters:
g - graphics context used for rendering

drawKeyUpdate

public void drawKeyUpdate(Graphics2D g)
Draws update required after keypress (call after keyUpdate)

Parameters:
g - graphics context used for rendering

drawAll

public void drawAll(Graphics2D g)
Draws all editor components and grid. (Warning: does not check whether levelset/level has been loaded)

Parameters:
g - graphics context used for rendering

getTestSet

public LevelSet getTestSet()
Returns levelset for testing (so can be loaded into GamePlayer .

Returns:
null if the Play/Test button has not been pressed.

cursorChange

public boolean cursorChange()
Indicates whether the cursor should be change (e.g. when moving to/from grid)

Returns:
true if the cursor needs to be changed

cursorChange

public boolean cursorChange(boolean exit)
Indicates whether the cursor should be change (e.g. when moving to/from grid)

Parameters:
exit - indicates whether the whole game screen has been left
Returns:
true if the cursor needs to be changed