dasher
Class CDasherViewSquare

java.lang.Object
  extended by dasher.CDasherComponent
      extended by dasher.CDasherView
          extended by dasher.CDasherViewSquare

public class CDasherViewSquare
extends CDasherView

An implementation (currently the one and only) of DasherView.

This draws all DasherNodes as a square aligned to the Y axis and with sizes dependent on their probability.

The horizontal and vertical scales are both subject to non-linearity; the x axis is linear at first and logarithmic after a given point, and the y axis is linear in all places but with different decreasing magnification factors towards the edges.


Nested Class Summary
protected  class CDasherViewSquare.Cymap
          Helper class which applies and unapplies the y-axis non-linearity.
(package private)  class CDasherViewSquare.D2Yret
          Small class for returning dashery2screen values, which compute two new y co-ordinates and a size attribute.
 
Nested classes/interfaces inherited from class dasher.CDasherView
CDasherView.DPoint, CDasherView.DRect, CDasherView.Point
 
Field Summary
protected  int CanvasY
          Height of our current screen in pixels
protected  long iLRScaleFactorX
          Cached values for scaling
protected  long iLRScaleFactorY
          Cached values for scaling
protected  long iTBScaleFactorX
          Cached values for scaling
protected  long iTBScaleFactorY
          Cached values for scaling
protected  int lpNormalisation
          Cache of LP_NORAMLIZATON
protected  int lpTruncation
          Cache of LP_TRUNCATION
protected  int lpTruncationType
          Cache of LP_TRUNCATION_TYPE
protected  double m_dXMappingLinearScaleFactor
          Scale factor applied to the linear portion of the x-axis nonlinearity.
protected  double m_dXMappingLogarithmicScaleFactor
          Scale factor applied to the logarithmic portion of the x-axis nonlinearity.
protected  double m_dXMappingLogLinearBoundary
          X co-ordinate at which we switch from linear to logarithmic magnification.
protected  CDasherView.DPoint m_iDasherMax
          Bottom-right corner of the current visible region
protected  CDasherView.DPoint m_iDasherMin
          Top-left corner of the current visible region
protected  long m_iScalingFactor
          The factor that scale factors are multipled by
protected  int m_yAutoOffset
          Nominally an offset which will be auto-calibrated and applied to input co-ordinates.
protected  CDasherViewSquare.Cymap m_ymap
          Helper for y mapping.
 
Fields inherited from class dasher.CDasherView
lpFontSize, lpMaxY, m_bVisibleRegionValid, m_DelayDraw, m_Input, m_Screen, realOrientation
 
Fields inherited from class dasher.CDasherComponent
m_EventHandler, m_SettingsStore
 
Constructor Summary
CDasherViewSquare(CEventHandler EventHandler, CSettingsStore SettingsStore, CDasherScreen DasherScreen)
          Sole constructor.
 
Method Summary
 double applyXMapping(double x)
          Apply the x co-ordinate nonlinearity.
 void ChangeScreen(CDasherScreen NewScreen)
          Sets a new screen, invalidates our current visible region, and recalls SetScalingFactor, since the relationships between Dasher and Screen co-ordinates may well have changed at this point.
 void Crosshair(long sx)
          Draws the Crosshair, with the vertical bar at a specified x co-ordinate and the horizontal bar halfway up the screen.
 CDasherView.Point Dasher2Screen(long iDasherX, long iDasherY)
          Converts Dasher co-ordinates to the Screen co-ordinate indicating the same location.
 int GetAutoOffset()
          Gets m_yAutoOffset, the y-coordinate screen offset to be applied for eyetracker devices.
 CDasherView.DPoint getInputDasherCoords()
          Calls getInputDasherCoords(mousex, mousey, null)
 CDasherView.DPoint getInputDasherCoords(java.util.ArrayList<CSymbolProb> Added)
          Gets the point in the Dasher world currently pointed to by our input device.
 CDasherView.DPoint GetScaleFactor(int eOrientation)
          Retrieves the x and y scaling factors relevant to our current orientation -- so iLRScaleFactorX and Y if we're in LeftToRight or RightToLeft modes, or their TB equivalents otherwise.
 void HandleEvent(CEvent Event)
          Method is called by the EventHandler when dispatching events.
 CDasherView.DPoint Input2Dasher(int iInputX, int iInputY, int iType, int iMode)
          Convert abstract 'input coordinates', which may or may not correspond to actual screen positions, depending on the settings, into dasher co-ordinates.
 boolean IsNodeVisible(long y1, long y2)
          Determines whether a node falls within our current visible region.
 void NewDrawGoTo(long iDasherMin, long iDasherMax, boolean bActive)
          Draws a square highlighting the area between two given y co-ordinates.
 void RecursiveRender(CDasherNode Render, long y1, long y2, int mostleft, java.util.Collection<CDasherNode> vNodeList, java.util.Collection<CDasherNode> vDeleteList)
          Recursively renders a tree of Nodes beginning at a given root, based on the following procedure:
 void RecursiveRenderGroups(SGroupInfo CurrentGroup, CDasherNode Node, long y1, long y2, int mostleft)
          Renders a given Group and all of its child groups by recursion.
 void RenderGroups(CDasherNode Render, long y1, long y2, int mostleft)
          Draws a given Node's grouping boxes, into which its Children are arranged.
 int RenderNode(int Color, EColorSchemes ColorScheme, long y1, long y2, int mostleft, java.lang.String sDisplayText, boolean bShove)
          Determines whether a given Node can be drawn, and if so, draws it.
 void RenderNodes(CDasherNode Root, long iRootMin, long iRootMax, java.util.Collection<CDasherNode> vNodeList, java.util.Collection<CDasherNode> vDeleteList)
          Draws a tree of nodes beginning at a given root.
 void ResetYAutoOffset()
          Sets m_yAutoOffset back to zero.
 CDasherView.DPoint Screen2Dasher(int iInputX, int iInputY, boolean b1D, boolean bNonlinearity)
          Convert screen co-ordinates to dasher co-ordinates.
 void SetScaleFactor()
          Computes a set of scaling factors for use in transforming screen to Dasher co-ordinates and vice versa.
 CDasherView.Point TruncateToScreen(int iX, int iY)
          Truncate a set of co-ordinates so that they are on the screen
 double unapplyXMapping(double x)
          Reverse the x co-ordinate nonlinearity.
 CDasherView.DRect VisibleRegion()
          Produces a rectangle showing the region of Dasher space which is currently visible on screen.
 double ymap(double x)
          Defers to m_ymap.map
 
Methods inherited from class dasher.CDasherView
DasherDrawCentredRectangle, DasherDrawRectangle, DasherDrawText, DasherPolygon, DasherPolyline, Display, GetCoordinateCount, GetCoordinates, Render, ResetSum, ResetSumCounter, Screen, SetInput, SpeedControl
 
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_dXMappingLogarithmicScaleFactor

protected double m_dXMappingLogarithmicScaleFactor
Scale factor applied to the logarithmic portion of the x-axis nonlinearity. Formerly known as m_dXmpa.


m_dXMappingLogLinearBoundary

protected double m_dXMappingLogLinearBoundary
X co-ordinate at which we switch from linear to logarithmic magnification. Formerly known as m_dXmpb.


m_dXMappingLinearScaleFactor

protected double m_dXMappingLinearScaleFactor
Scale factor applied to the linear portion of the x-axis nonlinearity. Formerly known as m_dXmpc.


CanvasY

protected int CanvasY
Height of our current screen in pixels


m_yAutoOffset

protected int m_yAutoOffset
Nominally an offset which will be auto-calibrated and applied to input co-ordinates. At present this is always zero.


m_ymap

protected CDasherViewSquare.Cymap m_ymap
Helper for y mapping.


iLRScaleFactorX

protected long iLRScaleFactorX
Cached values for scaling


iLRScaleFactorY

protected long iLRScaleFactorY
Cached values for scaling


iTBScaleFactorX

protected long iTBScaleFactorX
Cached values for scaling


iTBScaleFactorY

protected long iTBScaleFactorY
Cached values for scaling


m_iScalingFactor

protected long m_iScalingFactor
The factor that scale factors are multipled by


m_iDasherMin

protected CDasherView.DPoint m_iDasherMin
Top-left corner of the current visible region


m_iDasherMax

protected CDasherView.DPoint m_iDasherMax
Bottom-right corner of the current visible region


lpTruncation

protected int lpTruncation
Cache of LP_TRUNCATION


lpTruncationType

protected int lpTruncationType
Cache of LP_TRUNCATION_TYPE


lpNormalisation

protected int lpNormalisation
Cache of LP_NORAMLIZATON

Constructor Detail

CDasherViewSquare

public CDasherViewSquare(CEventHandler EventHandler,
                         CSettingsStore SettingsStore,
                         CDasherScreen DasherScreen)
Sole constructor. Creates a new view wrapping a specified screen, fires the ChangeScreen method to configure itself around said screen, creates a DelayedDraw object for String drawing, preloads our cached parameter values and sets certain hard-coded scaling factors, such as those used in the x-axis nonlinearity.

The specific values at present are:

Multiply all linear scaled values by 0.9, switch to logarithmic scaling from the midpoint of the axis, and multiply all log scaled values by 0.2.

Parameters:
EventHandler - Event handler with which to register ourselves
SettingsStore - Settings repository to use
DasherScreen - Screen to wrap and use for primitive drawing
Method Detail

HandleEvent

public void HandleEvent(CEvent Event)
Method is called by the EventHandler when dispatching events.

This class responds to the follow parameter-change events:

LP_REAL_ORIENTATION: Invalidates our current visible region.

LP_TRUNCATION, LP_TRUNCATION_TYPE, LP_NORMALIZATION: Updates internally cached values of these parameters.

Overrides:
HandleEvent in class CDasherView
Parameters:
Event - Event to handle

RenderNodes

public void RenderNodes(CDasherNode Root,
                        long iRootMin,
                        long iRootMax,
                        java.util.Collection<CDasherNode> vNodeList,
                        java.util.Collection<CDasherNode> vDeleteList)
Draws a tree of nodes beginning at a given root.

This function will call our screen's Blank method, and then call RecursiveRender on the Node we wish to draw. Once the RecursiveRender is finished, it will call m_DelayDraw's Draw method to draw all strings which have been queued up.

Finally, it will draw the Crosshair.

Specified by:
RenderNodes in class CDasherView
Parameters:
Root - Node at which to begin drawing
iRootMin - Bottom co-ordinate of the root node (in Dasher space)
iRootMax - Top co-ordinate of the root node (in Dasher space)
vNodeList - Collection which will be filled with drawn Nodes
vDeleteList - Collection which will be filled with undrawable Nodes

RecursiveRender

public void RecursiveRender(CDasherNode Render,
                            long y1,
                            long y2,
                            int mostleft,
                            java.util.Collection<CDasherNode> vNodeList,
                            java.util.Collection<CDasherNode> vDeleteList)
                     throws NodeCannotBeDrawnException
Recursively renders a tree of Nodes beginning at a given root, based on the following procedure:

  1. Calls RenderNode on this node, drawing it
  2. Calls RenderGroups on this node, drawing the grouping boxes for our children
  3. Recurses on each of our children in turn

Of course, if our children are not yet present, we return after step one.

This method also takes care of filling our Collections of drawable and undrawable nodes, by catching NodeCannotBeDrawnExceptions in the latter case.

'Shoving,' the process which keeps a child node's text from overlapping that of its parent, is also co-ordinated here; the new mostleft value returned by RenderNode is passed into the recursive calls which draw our children.

Parameters:
Render - Node at which to begin rendering
y1 - Top y co-ordinate of this Node
y2 - Bottom y co-ordinate of this Node
mostleft - Shoving parameter; see above
vNodeList - Collection to fill with drawn, childless Nodes
vDeleteList - Collection to fill with undrawable Nodes
Throws:
NodeCannotBeDrawnException

RenderGroups

public void RenderGroups(CDasherNode Render,
                         long y1,
                         long y2,
                         int mostleft)
Draws a given Node's grouping boxes, into which its Children are arranged. The simply calls RecursiveRenderGroups on each top-level group in turn, which does the actual drawing.

Parameters:
Render - Node whose grouping boxes we wish to draw
y1 - Top y co-ordinate of this Node
y2 - Bottom y co-ordinate of this Node
mostleft - Shoving parameter; indicates how far group labels should be displaced to the right in order to avoid overlapping parents' text.

RecursiveRenderGroups

public void RecursiveRenderGroups(SGroupInfo CurrentGroup,
                                  CDasherNode Node,
                                  long y1,
                                  long y2,
                                  int mostleft)
Renders a given Group and all of its child groups by recursion.

RenderNode is used to do the actual work of drawing the group boxes, and their sizes are determined by consulting the child list which this group delimits.

Parameters:
CurrentGroup - Group at which to start drawing
Node - Node of which this group is a child
y1 - Top Dasher co-ordinate of this group
y2 - Bottom Dasher co-ordinate of this group
mostleft - Shoving parameter; indicates how far group labels should be displaced to the right in order to avoid overlapping parents' text.

RenderNode

public int RenderNode(int Color,
                      EColorSchemes ColorScheme,
                      long y1,
                      long y2,
                      int mostleft,
                      java.lang.String sDisplayText,
                      boolean bShove)
               throws NodeCannotBeDrawnException
Determines whether a given Node can be drawn, and if so, draws it.

If the Node is undrawable because it's off the screen or is too small to sensibly draw, a NodeCannotBeDrawnException is thrown.

The drawing instruction is clipped to the visible region first, so the Screen should not be ordered to draw anything outside its bounds.

If truncation is enabled, it is applied here; if not, we simply call DasherDrawRectangle to form the Node box.

Lastly, the Node's text is added to m_DelayDraw to be drawn to the screen at the end of the drawing sequence.

This also generates a new mostleft value for shoving purposes, which is returned to our caller.

Parameters:
Color - Colour index to use for the node's background
ColorScheme - ColourScheme to use; usually ignored in favour of a colour index
y1 - Top y co-ordinate of this Node (Dasher space)
y2 - Bottom y co-ordinate of this Node (Dasher space)
mostleft - Shoving parameter; indicates how far node labels should be displaced to the right in order to avoid overlapping parents' text.
sDisplayText - Text to draw in this Node
bShove - Should we shove (report how far our text juts out, to help our caller avoid overlapping it)
Returns:
New value of mostleft (or that which was passed in, if we do not)
Throws:
NodeCannotBeDrawnException - if this Node cannot be drawn!

IsNodeVisible

public boolean IsNodeVisible(long y1,
                             long y2)
Determines whether a node falls within our current visible region. This is determined by the simple expedient of calling VisibleRegion and comparing the passed co-ordinates.

Overrides:
IsNodeVisible in class CDasherView
Parameters:
y1 - Node's top y co-ordinate
y2 - Node's bottom y co-ordinate
Returns:
True if falls within visible region, False otherwise

Screen2Dasher

public CDasherView.DPoint Screen2Dasher(int iInputX,
                                        int iInputY,
                                        boolean b1D,
                                        boolean bNonlinearity)
Convert screen co-ordinates to dasher co-ordinates. This doesn't include the nonlinear mapping for eyetracking mode etc - it is just the inverse of the mapping used to calculate the screen positions of boxes etc.

Specified by:
Screen2Dasher in class CDasherView
Parameters:
iInputX - Screen x co-ordinate
iInputY - Screen y co-ordinate
b1D - Should we use a simpler transform for 1D devices?
bNonlinearity - Should we use unapplyXMapping and m_ymap.unmap to reverse an applied nonlinearity?
Returns:
Point in Dasher space equivalent to the given Screen point

SetScaleFactor

public void SetScaleFactor()
Computes a set of scaling factors for use in transforming screen to Dasher co-ordinates and vice versa. This should be re-run any time the Screen's height or width are liable to have changed, or if we wish to change the size of the Dasher world's co-ordinate space.


GetScaleFactor

public CDasherView.DPoint GetScaleFactor(int eOrientation)
Retrieves the x and y scaling factors relevant to our current orientation -- so iLRScaleFactorX and Y if we're in LeftToRight or RightToLeft modes, or their TB equivalents otherwise.

Parameters:
eOrientation - Current orientation
Returns:
Dasher-world co-ordinate containing the width scaling factor as its x, and the height factor as its y.

Dasher2Screen

public CDasherView.Point Dasher2Screen(long iDasherX,
                                       long iDasherY)
Converts Dasher co-ordinates to the Screen co-ordinate indicating the same location.

Applies non-linearities to the Dasher co-ordinates using applyXMapping and m_ymap.map, before scaling appropriate to our current screen orientation.

Specified by:
Dasher2Screen in class CDasherView
Parameters:
iDasherX - Dasher x co-ordinate
iDasherY - Dasher y co-ordinate
Returns:
Screen point corresponding to this location

VisibleRegion

public CDasherView.DRect VisibleRegion()
Produces a rectangle showing the region of Dasher space which is currently visible on screen.

This is accomplished by the simple expedient of running Screen2Dasher against the minimum and maximum screen co-ordinates.

This function takes our current orientation into account in producing its answer.

Specified by:
VisibleRegion in class CDasherView
Returns:
Rectangle indicating the visible region.

Input2Dasher

public CDasherView.DPoint Input2Dasher(int iInputX,
                                       int iInputY,
                                       int iType,
                                       int iMode)
Convert abstract 'input coordinates', which may or may not correspond to actual screen positions, depending on the settings, into dasher co-ordinates. Modes are:

0 = Direct (ie mouse)
1 = 1D
2 = Eyetracker

This should be done once initially, then we work in Dasher co-ordinates for everything else. Input co-ordinates will be assumed to range over the extent of the screen.

Internally, we essentially

  1. Apply m_yAutoOffset to the y co-ordinate if this is an Eyetracker
  2. Feed screen co-ordinates through Screen2Dasher with the appropriate flags (1D and Nonlinear as necessary)
  3. Apply y co-ordinate scaling if this is a 1D device.

Specified by:
Input2Dasher in class CDasherView
Parameters:
iInputX - Input x co-ordinate
iInputY - Input y co-ordinate
iType - 0 if input co-ordinates are in pixels or 1 if in Dasher co-ordinates
iMode - See table above
Returns:
Dasher world point corresponding but not necessarily in the same place as this input point.

TruncateToScreen

public CDasherView.Point TruncateToScreen(int iX,
                                          int iY)
Truncate a set of co-ordinates so that they are on the screen

Parameters:
iX - Screen x co-ordinate
iY - Screen y co-ordinate
Returns:
Truncated point

getInputDasherCoords

public CDasherView.DPoint getInputDasherCoords()
Calls getInputDasherCoords(mousex, mousey, null)

Specified by:
getInputDasherCoords in class CDasherView
Returns:
Dasher co-ordinates corresponding to this input point

getInputDasherCoords

public CDasherView.DPoint getInputDasherCoords(java.util.ArrayList<CSymbolProb> Added)
Gets the point in the Dasher world currently pointed to by our input device.

Internally this boils down to calling GetCoordinates with the appropriate flags and then feeding the results through Input2Dasher.

Specified by:
getInputDasherCoords in class CDasherView
Parameters:
Added - Ignored, may be null
Returns:
Dasher co-ordinates corresponding to this input point

NewDrawGoTo

public void NewDrawGoTo(long iDasherMin,
                        long iDasherMax,
                        boolean bActive)
Draws a square highlighting the area between two given y co-ordinates.

Draws the square a different colour dependent on whether the 'active' flag is specified.

At present the colours are hard-coded: Colour 1 is used with a width of 3 for active, and colour 2 with a width of 1 for inactive.

Specified by:
NewDrawGoTo in class CDasherView
Parameters:
iDasherMin - Bottom y co-ordinate at which to align the square
iDasherMax - Top y co-ordinate at which to align the square
bActive - Draw this square in 'active' style?

ResetYAutoOffset

public void ResetYAutoOffset()
Sets m_yAutoOffset back to zero.

Overrides:
ResetYAutoOffset in class CDasherView

ChangeScreen

public void ChangeScreen(CDasherScreen NewScreen)
Sets a new screen, invalidates our current visible region, and recalls SetScalingFactor, since the relationships between Dasher and Screen co-ordinates may well have changed at this point.

Also caches the Screen's current height in CanvasY.

Overrides:
ChangeScreen in class CDasherView
Parameters:
NewScreen - New screen

GetAutoOffset

public int GetAutoOffset()
Gets m_yAutoOffset, the y-coordinate screen offset to be applied for eyetracker devices.

Overrides:
GetAutoOffset in class CDasherView
Returns:
0

ymap

public double ymap(double x)
Defers to m_ymap.map

Overrides:
ymap in class CDasherView
Parameters:
x - raw Y co-ordinate
Returns:
New y co-ordinate
See Also:
CDasherViewSquare.Cymap

Crosshair

public void Crosshair(long sx)
Draws the Crosshair, with the vertical bar at a specified x co-ordinate and the horizontal bar halfway up the screen.

The horizontal bar is hard coded to run from 12/14(sx) to 17/14(sx). This will cause trouble if sx is zero, and there will be issues if sx is small since we're working with integers, not floating point.

This method could do with being rewritten.

Specified by:
Crosshair in class CDasherView
Parameters:
sx - X co-ordinate for the vertical bar. Not zero, or the horizontal bar will not correctly display at present.

unapplyXMapping

public double unapplyXMapping(double x)
Reverse the x co-ordinate nonlinearity.

For details of this non-linearity, see the constructor.

Parameters:
x - Value to which the mapping should be unapplied
Returns:
Raw value

applyXMapping

public double applyXMapping(double x)
Apply the x co-ordinate nonlinearity.

For details of this non-linearity, see the constructor.

Overrides:
applyXMapping in class CDasherView
Parameters:
x - Value to which the mapping should be applied
Returns:
Mapped value