dasher
Class CDasherView

java.lang.Object
  extended by dasher.CDasherComponent
      extended by dasher.CDasherView
Direct Known Subclasses:
CDasherViewSquare

public abstract class CDasherView
extends CDasherComponent

Dasher views represent the visualisation of a Dasher model on the screen.

There are really three roles played by CDasherView: providing high level drawing functions, providing a mapping between Dasher co-ordinates and screen co-ordinates and providing a mapping between true and effective Dasher co-ordinates (eg for eyetracking mode).

This class supplies only those functions which are independent of the way in which we choose to represent the Model; the specifics are decided in subclasses which decide exactly how a node should be rendered. At present, the only subclass is DasherViewSquare which draws square boxes for each node.

Most actual drawing functions will be passed on to an implementation of CDasherScreen.


Nested Class Summary
static class CDasherView.DPoint
           
static class CDasherView.DRect
          Rectangle in Dasher space
static class CDasherView.Point
          Class representing a point on the screen.
 
Field Summary
protected  int lpFontSize
          Current font size used for drawing.
protected  long lpMaxY
          Stores the current value of LP_MAX_Y for efficiency.
protected  boolean m_bVisibleRegionValid
          Flag indicating whether we need to update our impression of the region in Dasher space which is currently visible.
protected  CDelayedDraw m_DelayDraw
          Delayed drawing helper.
protected  CDasherInput m_Input
          Current input device
protected  CDasherScreen m_Screen
          Screen we're currently using for drawing
protected  int realOrientation
          Stores the current value of LP_REAL_ORIENTATION again because this parameter is requested many times during drawing, which can become exceedingly inefficient.
 
Fields inherited from class dasher.CDasherComponent
m_EventHandler, m_SettingsStore
 
Constructor Summary
CDasherView(CEventHandler EventHandler, CSettingsStore SettingsStore, CDasherScreen DasherScreen)
          Creates a new View wrapping a specified screen.
 
Method Summary
 double applyXMapping(double x)
          Applies any desired co-ordinate nonlinearity in the X direction.
 void ChangeScreen(CDasherScreen NewScreen)
          Sets our screen.
protected abstract  void Crosshair(long sx)
          Draws the crosshair
abstract  CDasherView.Point Dasher2Screen(long iDasherX, long iDasherY)
          Should convert a given Dasher co-ordinate to its equivalent screen co-ordinates.
 void DasherDrawCentredRectangle(long iDasherX, long iDasherY, int iSize, int Color, EColorSchemes ColorScheme, boolean bDrawOutline)
          Draws a square with a given centre in Dasher co-ordinates and a given side-length in pixels (screen co-ordinates).
 void DasherDrawRectangle(long iLeft, long iTop, long iRight, long iBottom, int Color, int iOutlineColour, EColorSchemes ColorScheme, boolean bDrawOutline, boolean bFill, int iThickness)
          Draws a rectangle given its top-left and bottom-right co-ordinates in Dasher space.
 long DasherDrawText(long iAnchorX1, long iAnchorY1, long iAnchorX2, long iAnchorY2, java.lang.String sDisplayText, long mostleft, boolean bShove)
          Draws a given string inside a specified box, the dimensions and co-ordinates of which are given in Dasher co-ordinates.
 void DasherPolygon(long[] x, long[] y, int n, int iColour)
          Draws a filled polygon given a series of points in Dasher space.
 void DasherPolyline(long[] x, long[] y, int n, int iWidth, int iColour)
          Draws a polyline given a series of points in Dasher space.
 void Display()
          Deferred to our screen.
 int GetAutoOffset()
          Stub; Returns 0
 int GetCoordinateCount()
          Deferred to m_Input.
 int GetCoordinates(int iN, long[] Coordinates)
          Deferred to m_Input
abstract  CDasherView.DPoint getInputDasherCoords()
          Converts a pair of input co-ordinates to dasher co-ordinates.
abstract  CDasherView.DPoint getInputDasherCoords(java.util.ArrayList<CSymbolProb> Added)
          Converts a pair of input co-ordinates to dasher co-ordinates.
 void HandleEvent(CEvent event)
          This class responds to the following events:
protected abstract  CDasherView.DPoint Input2Dasher(int iInputX, int iInputY, int iType, int iMode)
          Converts input device co-ordinates to the appropriate, not necessarily equivalent, Dasher co-ordinates.
 boolean IsNodeVisible(long y1, long y2)
          Determines whether the node falling between two specified y co-ordinates is visible.
abstract  void NewDrawGoTo(long iDasherMin, long iDasherMax, boolean bActive)
          Draws a square aligned to the y axis and between given y co-ordinates
 boolean Render(CDasherNode Root, long iRootMin, long iRootMax, java.util.Collection<CDasherNode> vNodeList, java.util.Collection<CDasherNode> vDeleteList, boolean bRedrawDisplay)
          Renders the entire model, starting at a given Node and given specific bounds in Dasher space.
abstract  void RenderNodes(CDasherNode Root, long iRootMin, long iRootMax, java.util.Collection<CDasherNode> vNodeList, java.util.Collection<CDasherNode> vDeleteList)
          Render our nodes, beginning at a given node with given upper and lower y co-ordinates.
 void ResetSum()
          Stub
 void ResetSumCounter()
          Stub
 void ResetYAutoOffset()
          Stub
 CDasherScreen Screen()
          Gets our current screen
abstract  CDasherView.DPoint Screen2Dasher(int iInputX, int iInputY, boolean b1D, boolean bNonlinearity)
          Should convert a given screen co-ordinate to dasher co-ordinates.
 void SetInput(CDasherInput Input)
          Sets our current reference input device and informs the new device of our maximal co-ordinates.
 void SpeedControl(long iDasherX, long iDasherY, double dFrameRate)
          Applies auto speed control given the user's current input position in Dasher co-ordinates.
abstract  CDasherView.DRect VisibleRegion()
          Returns a rectangle indicating the area in Dasher space which is current visible.
 double ymap(double x)
          Applies any desired co-ordinate nonlinearity in the Y direction.
 
Methods inherited from class dasher.CDasherComponent
GetBoolParameter, GetLongParameter, GetParameterName, GetParameterType, GetStringParameter, InsertEvent, SetBoolParameter, SetLongParameter, SetStringParameter, UnregisterComponent
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_bVisibleRegionValid

protected boolean m_bVisibleRegionValid
Flag indicating whether we need to update our impression of the region in Dasher space which is currently visible.


m_Screen

protected CDasherScreen m_Screen
Screen we're currently using for drawing


m_Input

protected CDasherInput m_Input
Current input device


m_DelayDraw

protected CDelayedDraw m_DelayDraw
Delayed drawing helper. This allows us to draw Strings at the natural time, with the helper storing them and actually drawing all strings last.


lpMaxY

protected long lpMaxY
Stores the current value of LP_MAX_Y for efficiency.

We listen for parameter change events to update this when necessary.


realOrientation

protected int realOrientation
Stores the current value of LP_REAL_ORIENTATION again because this parameter is requested many times during drawing, which can become exceedingly inefficient.


lpFontSize

protected int lpFontSize
Current font size used for drawing.

Constructor Detail

CDasherView

public CDasherView(CEventHandler EventHandler,
                   CSettingsStore SettingsStore,
                   CDasherScreen DasherScreen)
Creates a new View wrapping a specified screen. The Screen passed must not be null; as such, the View must be created after a Screen has been instantiated.

To this ends, the View will usually be created in response to the first call to InterfaceBase.ChangeScreen().

This constructor will also initialise fields which cache parameter values, which will subsequently be kept up to date by listening for parameter change events.

Parameters:
EventHandler - Event handler with which to register ourselves
SettingsStore - Settings repository to use
DasherScreen - Screen object to wrap.
Method Detail

HandleEvent

public void HandleEvent(CEvent event)
This class responds to the following events:

LP_REAL_ORIENTATION, LP_MAX_Y and LP_DASHER_FONTSIZE: Updates our internally cached values of these parameters.

This method is called by the EventHandler when processing events.

Overrides:
HandleEvent in class CDasherComponent
Parameters:
event - Event to handle

ChangeScreen

public void ChangeScreen(CDasherScreen NewScreen)
Sets our screen. New drawing instructions will immediately being to be sent to the new one.

Parameters:
NewScreen - New screen

Render

public boolean Render(CDasherNode Root,
                      long iRootMin,
                      long iRootMax,
                      java.util.Collection<CDasherNode> vNodeList,
                      java.util.Collection<CDasherNode> vDeleteList,
                      boolean bRedrawDisplay)
Renders the entire model, starting at a given Node and given specific bounds in Dasher space.

At present this just passes all of its parameters to RenderNodes with the exception of bRedrawDisplay, which is ignored (the display is always redrawn).

Parameters:
Root - Node at which to start the drawing process
iRootMin - Minimum bounding co-ordinate in Dasher space
iRootMax - Maximum bounding co-ordinate in Dasher space
vNodeList - Collection which will be filled with Nodes which were drawn
vDeleteList - Collection which will be filled with Nodes which were not drawn
bRedrawDisplay - Flag indicating whether we wish for a redraw (ignored; always redraws)
Returns:
True if a redraw took place (always the case at the moment)

GetCoordinateCount

public int GetCoordinateCount()
Deferred to m_Input.

Returns:
Number of co-ordinates, or 0 if there is no input device.
See Also:
CDasherInput

GetCoordinates

public int GetCoordinates(int iN,
                          long[] Coordinates)
Deferred to m_Input

Parameters:
iN - Number of co-ordinates
Coordinates - Array to fill with co-ordinates
Returns:
0 if the returned co-ordinates are screen co-ordinates, 1 if Dasher co-ordinates. 0 will also be returned if there is currently no input device.

IsNodeVisible

public boolean IsNodeVisible(long y1,
                             long y2)
Determines whether the node falling between two specified y co-ordinates is visible.

Always returns true if not overridden.

Parameters:
y1 - upper y co-ordinate
y2 - lower y co-ordinate
Returns:
True if visible, false if not.

SetInput

public void SetInput(CDasherInput Input)
Sets our current reference input device and informs the new device of our maximal co-ordinates.

The input device will not be dereferenced or deleted, as the caller may be intending for the input device to switch frequently without destroying one which is nominally out of use.

Parameters:
Input - New input device

Display

public void Display()
Deferred to our screen.

See Also:
CDasherScreen

DasherPolyline

public void DasherPolyline(long[] x,
                           long[] y,
                           int n,
                           int iWidth,
                           int iColour)
Draws a polyline given a series of points in Dasher space.

Internally, we convert these to screen co-ordinates and pass the request on to our screen.

Specifying a line colour of -1 causes the default to be drawn.

Parameters:
x - Array of points' x co-ordinates
y - Array of points' y co-ordinates
n - Number of points in the line
iWidth - Line width
iColour - Colour index (-1 means default colour)

DasherPolygon

public void DasherPolygon(long[] x,
                          long[] y,
                          int n,
                          int iColour)
Draws a filled polygon given a series of points in Dasher space.

Internally, we convert these to screen co-ordinates and pass the request on to our screen.

Specifying a colour of -1 is not handled specially by this method but ought to be translated to some sensible default by the Screen.

Parameters:
x - Array of points' x co-ordinates
y - Array of points' y co-ordinates
n - Number of points specified
iColour - Colour index (-1 means default colour)

DasherDrawRectangle

public void DasherDrawRectangle(long iLeft,
                                long iTop,
                                long iRight,
                                long iBottom,
                                int Color,
                                int iOutlineColour,
                                EColorSchemes ColorScheme,
                                boolean bDrawOutline,
                                boolean bFill,
                                int iThickness)
Draws a rectangle given its top-left and bottom-right co-ordinates in Dasher space.

The co-ordinates are translated to screen co-ordinates and the request passed on to the screen.

Parameters:
iLeft - Left side x co-ordinate
iTop - Top y co-ordinate
iRight - Right side x co-ordinate
iBottom - Bottom y co-ordinate
Color - Fill colour
iOutlineColour - Outline colour
ColorScheme - Colour scheme to use (usually ignored in favour of colour indices now)
bDrawOutline - Should we draw an outline?
bFill - Filled?
iThickness - Outline thickness

DasherDrawCentredRectangle

public void DasherDrawCentredRectangle(long iDasherX,
                                       long iDasherY,
                                       int iSize,
                                       int Color,
                                       EColorSchemes ColorScheme,
                                       boolean bDrawOutline)
Draws a square with a given centre in Dasher co-ordinates and a given side-length in pixels (screen co-ordinates).

Parameters:
iDasherX - Centre point x co-ordinate
iDasherY - Centre point y co-ordinate
iSize - Side length in pixels
Color - Fill colour index
ColorScheme - Colour scheme (usually ignored now in favour of colour index)
bDrawOutline - Whether to draw a hairline black outline

DasherDrawText

public long DasherDrawText(long iAnchorX1,
                           long iAnchorY1,
                           long iAnchorX2,
                           long iAnchorY2,
                           java.lang.String sDisplayText,
                           long mostleft,
                           boolean bShove)
Draws a given string inside a specified box, the dimensions and co-ordinates of which are given in Dasher co-ordinates.

The actual specified bounding box is more or less taken as a guideline however, and many changes are made from that which is specified to the drawing command which is actually issued.

The most important change is that, using the mostleft parameter to indicate the right-hand edge of some ancestor's text, an effort is made to 'shove' this text to the right far enough that it does not overlap with our ancestor.

This feature is enabled only when bShove is true.

The font size to be used to draw text is currently hard coded so that text within 15 pixels of the y axis is drawn at size 11, between 15 and 30 pixels is drawn at size 14, and over 30 pixels is drawn at size 20.

The bounding box is recalculated by calling the Screen's TextSize method, which attempts to determine the dimensions of this string at a given size. This is then used to work out how far our children's text must be 'shoved' to avoid overlapping our own.

As such, this method is far from general, and should only be used to draw node labels. A new method will be required if the need arises to draw arbitrary strings in a specified location without adjustment.

This method will return a new 'mostleft' value for use when drawing our children; if the Screen's TextSize method is accurate, this ought to prevent our text from overlapping that of our children.

For the actual drawing of text, m_DelayDraw is used instead of passing the command directly to our Screen. This queue of text to draw will be emptied towards the end of the drawing cycle.

Parameters:
iAnchorX1 - Left edge x co-ordinate
iAnchorY1 - Top edge y co-ordinate
iAnchorX2 - Right edge x co-ordinate
iAnchorY2 - Bottom edge y co-ordinate
sDisplayText - String to draw
mostleft - Co-ordinate of the right-most text drawn by our ancestor.
bShove - Should we try to avoid overlapping ancestor's text?
Returns:
New 'mostleft' value for drawing children

RenderNodes

public abstract void RenderNodes(CDasherNode Root,
                                 long iRootMin,
                                 long iRootMax,
                                 java.util.Collection<CDasherNode> vNodeList,
                                 java.util.Collection<CDasherNode> vDeleteList)
Render our nodes, beginning at a given node with given upper and lower y co-ordinates.

Will also fill vNodeList with a list of nodes which were successfully drawn, and vDeleteList with a list of those whom we abandoned drawing because they were off screen, too small, etc.

Parameters:
Root - Node at which to start drawing
iRootMin - Lower y co-ordinate of this node
iRootMax - Upper y co-ordinate of this node
vNodeList - Collection to be filled with drawn nodes
vDeleteList - Collection to be filled with undrawn nodes

getInputDasherCoords

public abstract CDasherView.DPoint getInputDasherCoords()
Converts a pair of input co-ordinates to dasher co-ordinates.

Also takes account of the type of input device we're using, so that one-dimensional devices and eyetrackers are corrected appropriately.

This method has been renamed from TapOnDisplay

Returns:
Dasher co-ordinates corresponding to this input point

getInputDasherCoords

public abstract CDasherView.DPoint getInputDasherCoords(java.util.ArrayList<CSymbolProb> Added)
Converts a pair of input co-ordinates to dasher co-ordinates.

Also takes account of the type of input device we're using, so that one-dimensional devices and eyetrackers are corrected appropriately.

This last parameter is redundant.

This method has been renamed from TapOnDisplay

Parameters:
Added - Redundant
Returns:
Dasher co-ordinates corresponding to this input point

Screen2Dasher

public abstract CDasherView.DPoint Screen2Dasher(int iInputX,
                                                 int iInputY,
                                                 boolean b1D,
                                                 boolean bNonlinearity)
Should convert a given screen co-ordinate to dasher co-ordinates.

Parameters:
iInputX - Screen x co-ordinate
iInputY - Screen y co-ordinate
b1D - Indicates whether these co-ordinates come from a 1D device
bNonlinearity - If true, we may wish to correct for a non-linearity in one or other co-ordinate system
Returns:
Dasher co-ordinates

Dasher2Screen

public abstract CDasherView.Point Dasher2Screen(long iDasherX,
                                                long iDasherY)
Should convert a given Dasher co-ordinate to its equivalent screen co-ordinates.

Parameters:
iDasherX - Dasher x co-ordinate
iDasherY - Dasher y co-ordinate
Returns:
Screen co-ordinates

Input2Dasher

protected abstract CDasherView.DPoint Input2Dasher(int iInputX,
                                                   int iInputY,
                                                   int iType,
                                                   int iMode)
Converts input device co-ordinates to the appropriate, not necessarily equivalent, Dasher co-ordinates.

Parameters:
iInputX - Input x co-ordinate
iInputY - Input y co-ordinate
iType - Input co-ordinate scheme: 0 for Screen or 1 for Dasher co-ordintes
iMode - Input device mode; 0 for normal, 1 for 1D and 2 for eyetracker
Returns:
Dasher co-ordinates corresponding to given input co-ordinates

GetAutoOffset

public int GetAutoOffset()
Stub; Returns 0

Returns:
0

NewDrawGoTo

public abstract void NewDrawGoTo(long iDasherMin,
                                 long iDasherMax,
                                 boolean bActive)
Draws a square aligned to the y axis and between given y co-ordinates

Parameters:
iDasherMin - Bottom y co-ordinate
iDasherMax - Top y co-ordinate
bActive - Affects colouring

Screen

public CDasherScreen Screen()
Gets our current screen

Returns:
Current screen

ResetSum

public void ResetSum()
Stub


ResetSumCounter

public void ResetSumCounter()
Stub


ResetYAutoOffset

public void ResetYAutoOffset()
Stub


SpeedControl

public void SpeedControl(long iDasherX,
                         long iDasherY,
                         double dFrameRate)
Applies auto speed control given the user's current input position in Dasher co-ordinates.

Parameters:
iDasherX - x co-ordinate
iDasherY - y co-ordinate
dFrameRate - Current frame rate in FPS

applyXMapping

public double applyXMapping(double x)
Applies any desired co-ordinate nonlinearity in the X direction.

Both input and output are co-ordinates in Dasher space.

Returns 0 in this base class; must be overridden if used.

Parameters:
x - raw X co-ordinate
Returns:
New x co-ordinate

ymap

public double ymap(double x)
Applies any desired co-ordinate nonlinearity in the Y direction.

Both input and output are co-ordinates in Dasher space.

Returns 0 in this base class; must be overridden if used.

Parameters:
x - raw Y co-ordinate
Returns:
New y co-ordinate

VisibleRegion

public abstract CDasherView.DRect VisibleRegion()
Returns a rectangle indicating the area in Dasher space which is current visible.

Returns:
Visible region

Crosshair

protected abstract void Crosshair(long sx)
Draws the crosshair

Parameters:
sx - X co-ordinate at which to draw the crossbeam