org.zaval.misc
Class PosController

java.lang.Object
  |
  +--org.zaval.util.ValidationObject
        |
        +--org.zaval.misc.PosController
All Implemented Interfaces:
Validationable
Direct Known Subclasses:
MaskPosController

public class PosController
extends ValidationObject

This class can be used to organize navigation along an object. The class allows to control virtual position basing on the navigation object information. The information should be provided by implementing PosInfo interface with the object. The interface defines number of virtual lines, size of the specified virtual line and so on.


Field Summary
static int BEG
          The begining direction type.
static int DOWN
          The down direction type.
static int END
          The end direction type.
protected  int prevCol
           
protected  int prevLine
           
protected  int prevOffset
           
static int UP
          The up direction type.
 
Fields inherited from class org.zaval.util.ValidationObject
isValidFlag
 
Constructor Summary
PosController()
          Constructs the new instance of the class.
PosController(PosInfo pi)
          Constructs the new instance of the class with the specified pos info.
 
Method Summary
 void addPosListener(PosListener l)
          Adds the specified PosListener listener.
static int calcMaxOffset(PosInfo pi)
          Calculates and returns the maximal offset for the specified pos info.
 void clearPos()
          Sets the virtual position to undefined state.
 int getCurrentCol()
          Gets the current column inside the current line.
 int getCurrentLine()
          Gets the current line.
 int getMaxOffset()
          Gets the maximal possible position value.
 int getOffset()
          Gets the current position.
static int getOffsetByPoint(int row, int col, PosController pc)
          Gets an offset by the specified text line and column for the specified controller.
static java.awt.Point getPointByOffset(int offset, PosController pc)
          Gets a line number and a column number by the specified text offset for the specified controller.
 PosInfo getPosInfo()
          Gets the pos info.
protected  void perform(PosEvent e)
          Fires the specified PosEvent to pos listeners.
protected  void recalc()
          Invoked with validate method in a case if the object is not valid.
 void removePosListener(PosListener l)
          Removes the specified PosListener listener.
 void seek(int off)
          Moves the current position by additing specified value.
 void seekLineTo(int t)
          Moves the current position to the next line according to the specified direction.
 void seekLineTo(int t, int num)
          Moves the current position to the next line according the specified direction and count.
 void setOffset(int o)
          Sets the specified virtual position.
 void setPosInfo(PosInfo p)
          Sets the specified pos info.
 void setRowCol(int r, int c)
          Sets the current position by the specified row and column.
 
Methods inherited from class org.zaval.util.ValidationObject
invalidate, isValid, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DOWN

public static final int DOWN
The down direction type.

UP

public static final int UP
The up direction type.

BEG

public static final int BEG
The begining direction type.

END

public static final int END
The end direction type.

prevOffset

protected int prevOffset

prevCol

protected int prevCol

prevLine

protected int prevLine
Constructor Detail

PosController

public PosController()
Constructs the new instance of the class.

PosController

public PosController(PosInfo pi)
Constructs the new instance of the class with the specified pos info.
Parameters:
pi - the specified pos info.
Method Detail

setPosInfo

public void setPosInfo(PosInfo p)
Sets the specified pos info. It is impossible to use null value as the pos info, in this case the IllegalArgumentException will be thrown.
Parameters:
p - the specified pos info.

clearPos

public void clearPos()
Sets the virtual position to undefined state. The position is undefined if it less than zero.

setOffset

public void setOffset(int o)
Sets the specified virtual position. If the new position is less than zero than the method will set zero as the position value, if the new position is greater than maximal than the method sets the maximal offset as the position value.
Parameters:
o - the specified virtual position.

seek

public void seek(int off)
Moves the current position by additing specified value. The method works by setOffset method.
Parameters:
off - the specified value.

setRowCol

public void setRowCol(int r,
                      int c)
Sets the current position by the specified row and column. The method works by setOffset method.
Parameters:
r - the specified row.
c - the specified column.

seekLineTo

public void seekLineTo(int t)
Moves the current position to the next line according to the specified direction. The table below shows how the method works depending on the direction type:
Direction typeDescription
PosController.DOWN Moves the current position to the next line below. The controller tries to set the column that has been used for previous line if it is possible, otherwise the new column will be set to the maximal column of the new line.
PosController.UP Moves the current position to the next line above. The controller tries to set the column that has been used for previous line if it is possible, otherwise the new column will be set to the maximal column of the new line.
PosController.END Moves the current position to the end of the current line.
PosController.BEG Moves the current position at the beginning of the current line.
Parameters:
t - the specified direction.

seekLineTo

public void seekLineTo(int t,
                       int num)
Moves the current position to the next line according the specified direction and count. The table below shows how the method works depending on the direction type:
Direction typeDescription
PosController.DOWN Moves the current position to the next line below. The controller tries to set the column that has been used for previous line if it is possible, otherwise the new column will be set to the maximal column of the new line.
PosController.UP Moves the current position to the next line above. The controller tries to set the column that has been used for previous line if it is possible, otherwise the new column will be set to the maximal column of the new line.
PosController.END Moves the current position to the end of the current line.
PosController.BEG Moves the current position at the beginning of the current line.
The count defines how many times the current position will be changed using the given direction.
Parameters:
t - the specified direction.
num - the specified count.

getMaxOffset

public int getMaxOffset()
Gets the maximal possible position value. The method uses pos info object to define the maximal value by getMaxOffset method. If the pos info method returns -1 than the method will calculate maximal position basing on the number of lines and the appropriate lines sizes.
Returns:
a maximal possible position value.

getCurrentCol

public int getCurrentCol()
Gets the current column inside the current line.
Returns:
a current column.

getCurrentLine

public int getCurrentLine()
Gets the current line.
Returns:
a current line.

getOffset

public int getOffset()
Gets the current position.
Returns:
a current position.

recalc

protected void recalc()
Description copied from class: ValidationObject
Invoked with validate method in a case if the object is not valid.
Overrides:
recalc in class ValidationObject

addPosListener

public void addPosListener(PosListener l)
Adds the specified PosListener listener.
Parameters:
l - the specified listener.

removePosListener

public void removePosListener(PosListener l)
Removes the specified PosListener listener.
Parameters:
l - the specified listener.

getPosInfo

public PosInfo getPosInfo()
Gets the pos info.
Returns:
a pos info.

perform

protected void perform(PosEvent e)
Fires the specified PosEvent to pos listeners.
Parameters:
e - the specified pos event.

getPointByOffset

public static java.awt.Point getPointByOffset(int offset,
                                              PosController pc)
Gets a line number and a column number by the specified text offset for the specified controller.
Parameters:
offset - the specified offset.
pc - the specified position controller.
Returns:
the Point object where the x field is the line number and the y field is the column number.

getOffsetByPoint

public static int getOffsetByPoint(int row,
                                   int col,
                                   PosController pc)
Gets an offset by the specified text line and column for the specified controller.
Parameters:
row - the specified text line number.
col - the specified text column number.
pc - the specified position controller.
Returns:
the offset.

calcMaxOffset

public static int calcMaxOffset(PosInfo pi)
Calculates and returns the maximal offset for the specified pos info.
Parameters:
pi - the specified pos info.
Returns:
a maximal offset.


Copyright © Zaval Creative Engineering Group, 2000-2005.
http://www.zaval.org