|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectdasher.CDasherInterfaceBase
public abstract class CDasherInterfaceBase
DasherInterfaceBase is the core of Dasher, and the entry point for all high-level functions which control the system as a whole.
The majority of the actual work involved in running Dasher is done by the Interface's two main children, a DasherModel and a DasherView; the interface primarily acts as a co-ordinator.
The DasherModel represents the tree of DasherNodes which forms the core of Dasher. It knows how to update the model in response to user input, and how to build, destroy and rebuild the tree.
The DasherView on the other hand is responsible for taking the abstract information in the Model and rendering it, visually or otherwise, in some way.
the Interface simply sits in the middle and co-ordinates whole-system actions such as updating the model and drawing a new frame.
The interface has a number of methods which remain abstract; this means that in order to implement Dasher, this class must be extended and the missing methods implemented.
Typically one would also extend DasherInput to provide a co-ordinate input of some sort, and implement DasherScreen to provide visual (or other) display.
| Field Summary | |
|---|---|
CFileLogger |
g_Logger
|
protected CAlphabet |
m_Alphabet
Current alphabet |
protected CAlphIO |
m_AlphIO
Current AlphIO |
protected boolean |
m_bConnectLock
Lock engaged when we're in the process of connecting to a remote language model |
protected boolean |
m_bGlobalLock
Lock engaged when Dasher should not respond to commands for unspecified reason |
protected boolean |
m_bShutdownLock
Lock engaged when Dasher is being destroyed |
protected CColourIO |
m_ColourIO
Current ColourIO |
protected CCustomColours |
m_Colours
Current colour scheme |
protected CDasherModel |
m_DasherModel
Current DasherModel |
protected CDasherScreen |
m_DasherScreen
Current DasherScreen |
protected CDasherView |
m_DasherView
Current DasherView |
protected CEventHandler |
m_EventHandler
Our event handler |
protected CDasherInput |
m_Input
Current Input device |
protected CInputFilter |
m_InputFilter
Current input filter |
protected CModuleManager |
m_oModuleManager
The module manager |
protected CSettingsStore |
m_SettingsStore
Our settings repository |
protected CUserLog |
m_UserLog
Our logging module |
protected java.util.LinkedList<java.lang.Character> |
strCurrentContext
Context of recently entered characters |
protected java.lang.StringBuffer |
strTrainfileBuffer
Entered text which has not yet been written out to disk |
| Constructor Summary | |
|---|---|
CDasherInterfaceBase()
Sole constructor. |
|
| Method Summary | |
|---|---|
void |
ChangeAlphabet()
Changes the alphabet in use to that described by SP_ALPHABET_ID. |
void |
ChangeColours()
Changes the colour scheme to that described by SP_COLOUR_ID. |
void |
ChangeScreen(CDasherScreen NewScreen)
Changes the Screen to which we should send drawing instructions. |
void |
ChangeView()
Creates an instance of DasherViewSquare, and, if they are present, informs it of our current Input Filter and Screen. |
void |
ConnectNode(int iChild,
int iParent,
int iAfter)
Deferred to m_DasherModel. |
void |
CreateDasherModel()
Creates a new DasherModel, deleting any previously existing one if necessary. |
void |
CreateFactories()
Manually registers a number of input filters. |
void |
CreateInput()
Creates an input device by calling GetModuleByName on the parameter SP_INPUT_DEVICE. |
void |
CreateInputFilter()
Creates m_InputFilter by retrieving the module named in SP_INPUT_FILTER. |
abstract void |
CreateSettingsStore()
Should create a SettingsStore object of some sort and store a reference to it in m_SettingsStore. |
void |
DeleteAlphabet(java.lang.String AlphID)
Deferred to m_AlphIO |
void |
DestroyInterface()
Instructs all componenets to unregister themselves with the event handler, and nulls our pointers to them, such that they will be available for garbage collection. |
void |
DisconnectNode(int iChild,
int iParent)
Deferred to m_DasherModel. |
CAlphIO |
doAlphIO(java.util.ArrayList<java.lang.String> vFiles)
Reads a list of XML files and returns an instance of CAlphIO which knows about the alphabets found in these files. |
CColourIO |
doColourIO(java.util.ArrayList<java.lang.String> vFiles)
Reads a list of XML files and returns an instance of CColourIO which knows about the colours found in these files. |
void |
Draw(boolean bRedrawNodes)
Completely draws the screen based on the current state of the model, taking into account whether the model has changed since the last frame. |
void |
ExternalEventHandler(CEvent Event)
Called for every dispatched event after all components have received it and *after* InterfaceEventHandler. |
CAlphabet |
GetAlphabet()
Gets the current alphabet |
void |
GetAlphabets(java.util.ArrayList<java.lang.String> AlphabetList)
Deferred to m_AlphIO |
int |
GetAutoOffset()
Deferred to m_DasherView. |
boolean |
GetBoolParameter(Ebp_parameters iParameter)
Deferred to CSettingsStore |
void |
GetColours(java.util.ArrayList<java.lang.String> ColourList)
Deferred to m_ColourIO |
double |
GetCurCPM()
Stub. |
double |
GetCurFPS()
Stub. |
CEventHandler |
GetEventHandler()
Retrieves the EventHandler created during this class' construction, and which calls this interface to handle events. |
abstract int |
GetFileSize(java.lang.String strFileName)
Should return the size of a given file, or 0 if the file does not exist or cannot be accessed. |
void |
GetFontSizes(java.util.Collection<java.lang.Integer> FontSizes)
Retrieves a list of available font sizes. |
CAlphIO.AlphInfo |
GetInfo(java.lang.String AlphID)
Deferred to m_AlphIO |
long |
GetLongParameter(Elp_parameters iParameter)
Deferred to CSettingsStore |
CDasherModule |
GetModule(long iID)
Deferred to m_oModuleManager |
CDasherModule |
GetModuleByName(java.lang.String strName)
Deferred to m_oModuleManager |
double |
GetNats()
Deferred to CDasherModel |
java.io.InputStream |
getResourceStream(java.lang.String filename)
This will be called by a number of file I/O methods when ordinary file I/O fails; it is intended for implementations to override it if they wish to return a stream pointing to JAR-packed files, remote network locations, etc. |
java.lang.String |
GetStringParameter(Esp_parameters iParameter)
Deferred to CSettingsStore |
CUserLog |
GetUserLogPtr()
Gets a reference to m_UserLog. |
void |
Halt()
Pauses Dasher and calls DasherModel.Halt(). |
void |
InterfaceEventHandler(CEvent Event)
This is called by the EventHandler after all other components have received this event. |
void |
InvalidateContext(boolean bForceStart)
Attempts to retrieve a fresh context by dispatching an EditContextEvent, which has a field to return a new context if anybody hearing the event chose to submit one. |
void |
KeyDown(long iTime,
int iId)
Signals a key press to our input filter. |
void |
KeyUp(long iTime,
int iId)
Signals a key press to our input filter. |
void |
NewFrame(long iTime)
Encapsulates the entire process of drawing a new frame of the Dasher world. |
void |
PauseAt(int MouseX,
int MouseY)
Pauses Dasher at a given mouse location, and sets BP_REDRAW so that a full redraw will be performed next frame. |
void |
PreSetNotify(Esp_parameters iParameter,
java.lang.String sNewValue)
Notifies the interface before a string parameter is changed. |
void |
Realize()
Realize does the bulk of the work of setting up a working Dasher. |
abstract void |
Redraw(boolean bChanged)
Abstract method which will be called whenever a screen redraw is required. |
void |
RegisterFactory(CModuleFactory Factory)
Deferred to m_oModuleManager |
void |
RegisterNode(int iID,
java.lang.String strLabel,
int iColour)
Deferred to m_DasherModel. |
void |
ResetNats()
Passed on to CDasherModel, if it is non-null. |
void |
ResetParameter(EParameters iParameter)
Deferred to CSettingsStore |
abstract void |
ScanAlphabetFiles(java.util.Collection<java.lang.String> vFileList)
Somehow determines which alphabet XML files to parse. |
abstract void |
ScanColourFiles(java.util.Collection<java.lang.String> vFileList)
Somehow determines which colour XML files to parse. |
void |
SetBoolParameter(Ebp_parameters iParameter,
boolean bValue)
Deferred to CSettingsStore |
void |
SetInfo(CAlphIO.AlphInfo NewInfo)
Deferred to m_AlphIO |
void |
SetLongParameter(Elp_parameters iParameter,
long lValue)
Deferred to CSettingsStore |
void |
SetStringParameter(Esp_parameters iParameter,
java.lang.String sValue)
Deferred to CSettingsStore |
abstract void |
SetupPaths()
Should setup the system and user locations; called early in the startup sequence. |
abstract void |
SetupUI()
Should perform any UI building which is required. |
void |
Start()
Simply calls DasherModel.Start() and DasherView.ResetYAutoOffset() so see these functions' documentation for detail. |
void |
StartShutdown()
Engages the shutdown lock (m_bShutdownLock). |
int |
TrainFile(java.lang.String Filename,
int iTotalBytes,
int iOffset)
Trains our Model from the text found in a given file, which must be UTF-8 encoded. |
int |
TrainStream(java.io.InputStream FileIn,
int iTotalBytes,
int iOffset)
Trains the language model from a given InputStream, which must be UTF-8 encoded. |
void |
Unpause(long Time)
Unpause Dasher. |
void |
WriteTrainFile(java.lang.String strNewText)
Stub. |
protected void |
WriteTrainFileFull()
Writes the text entered by the user as a training file. |
protected void |
WriteTrainFilePartial()
Writes the first 100 characters of user-entered text as a training file. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public CFileLogger g_Logger
protected CAlphabet m_Alphabet
protected CCustomColours m_Colours
protected CDasherModel m_DasherModel
protected CDasherScreen m_DasherScreen
protected CDasherView m_DasherView
protected CDasherInput m_Input
protected CAlphIO m_AlphIO
protected CColourIO m_ColourIO
protected java.lang.StringBuffer strTrainfileBuffer
protected java.util.LinkedList<java.lang.Character> strCurrentContext
protected CEventHandler m_EventHandler
protected CSettingsStore m_SettingsStore
protected CUserLog m_UserLog
protected CInputFilter m_InputFilter
protected CModuleManager m_oModuleManager
protected boolean m_bGlobalLock
protected boolean m_bShutdownLock
protected boolean m_bConnectLock
| Constructor Detail |
|---|
public CDasherInterfaceBase()
Realize() must be called after construction and before any other functions which depend upon anything other than the event handler and module manager.
| Method Detail |
|---|
public abstract void ScanAlphabetFiles(java.util.Collection<java.lang.String> vFileList)
vFileList - List to fill with filenames to process.public abstract void ScanColourFiles(java.util.Collection<java.lang.String> vFileList)
vFileList - List to fill with filenames to process.public abstract void SetupPaths()
These correspond to the string parameters SP_SYSTEM_LOC and SP_USER_LOC respectively.
public abstract void SetupUI()
public abstract void CreateSettingsStore()
This is an abstract method because most implementations will want to extend the default SettingsStore to provide the possibility of persistent settings.
public abstract int GetFileSize(java.lang.String strFileName)
strFileName - File to be read
public void Realize()
When realize terminates, Dasher will be in a broadly usable state. It will still lack a co-ordinate input device, which should be registered with RegisterFactory, and will need a Screen which should be created externally and registered with ChangeScreen, but will otherwise be good to go.
public void DestroyInterface()
public void PreSetNotify(Esp_parameters iParameter,
java.lang.String sNewValue)
This enables the interface to read the parameter's current value if necessary.
Presently the interface responds to:
SP_ALPHABET_ID: Stores a history of previous used alphabets in SP_ALPHABET_1, SP_ALPHABET_2 and so on.
iParameter - Parameter which is going to change.sNewValue - Value to which it will change.public void InterfaceEventHandler(CEvent Event)
The interface responds to the following parameter changes:
BP_COLOUR_MODE: Calls Start() and redraws the display.
BP_OUTLINE_MODE: Redraws the display.
BP_CONNECT_LOCK: Sets the internal m_bConnectLock variable.
LP_ORIENTATION: Sets the LP_REAL_ORIENTATION parameter either to the value of LP_ORIENTATION, or if the latter is -2 (a special sentinel value) queries the current alphabet for its preferred orientation, and sets LP_REAL_ORIENTATION appropriately.
SP_ALPHABET_ID: Calls ChangeAlphabet() to rebuild the DasherModel appropriately, and then Start().
SP_COLOUR_ID: Calls ChangeColours() to insert the new colour scheme.
BP_PALETTE_CHANGE and SP_DEFAULT_COLOUR_ID: If Palette Change is true, changes COLOUR_ID to match DEFAULT_COLOUR_ID which contains the current alphabet's preferred colour scheme.
LP_LANGUAGE_MODEL_ID: Runs CreateDasherModel() to rebuild the model based on our newly chosen language model.
SP_LM_HOST: If we are currently using a remote language model, rebuilds the Model as above; otherwise, ignores.
LP_DASHER_FONTSIZE and LP_LINE_WIDTH: Redraws the display.
SP_INPUT_FILTER: Runs CreateInputFilter() to recreate the requested filter.
SP_INPUT_DEVICE: Runs CreateInput() to create the requested input device.
It also responds to EditEvents by modifying strCurrentContext according to the text the user is reported to have entered or deleted, and LockEvents by setting m_bGlobalLock to the value indicated.
Event - The event the interface is to process.public CAlphIO doAlphIO(java.util.ArrayList<java.lang.String> vFiles)
This class does it by the simple expedient of creating a new CAlphIO and passing these files, but some extensions may redirect the request in the case that the XML files have already been parsed.
vFiles - List of files to be parsed
public CColourIO doColourIO(java.util.ArrayList<java.lang.String> vFiles)
This class does it by the simple expedient of creating a new CColourIO and passing these files, but some extensions may redirect the request in the case that the XML files have already been parsed.
vFiles - List of files to be parsed
public void CreateDasherModel()
The DasherModel does most of the actual initialisation work, so see the constructor documentation for DasherModel for details.
This function will also set m_Alphabet to that created in the course of the DasherModel's initialisation, and will train the newly created model using the new Alphabet's specified training text.
public void Start()
public void PauseAt(int MouseX,
int MouseY)
Also generates a StopEvent to notify other components.
MouseX - Mouse x co-ordinate at the time of stoppingMouseY - Mouse y co-ordinate at the time of stoppingpublic void Halt()
This function, unlike PauseAt, does not throw a StopEvent.
public void Unpause(long Time)
Time - System time as a UNIX timestamp at which Dasher was restarted.public void CreateInput()
If there is an existing input device, it will be Unref'd and Deactivated first.
In the event that a non-null DasherInput class is created, its Ref and Activate methods will be called immediately.
CDasherInput,
CModuleManagerpublic void NewFrame(long iTime)
We invoke our input filter's Timer method, which determines in what way the Model should be updated, if at all, allow the Model to check its consistency after being changed, and then finally ask our View to draw the newly updated world.
Method will return without any action if any of the three lock variables are true.
iTime - Current system time as a UNIX time stamp.public void Draw(boolean bRedrawNodes)
This breaks down to calling the Model's RenderToView method if we need to draw the nodes, and then calling the InputFilter's DecorateView method.
The View's Display() method is called only in the event that anything has changed.
At present, this is hacked such that it always does a full redraw if Dasher is unpaused, owing to the fact that the Java front-end must receive a frame every time it calls Draw. See the documentation for applet.JDasherScreen for details.
bRedrawNodes - True if the Model has changed since the last frame.JDasherScreenpublic abstract void Redraw(boolean bChanged)
bChanged - True if the model has changed since the last framepublic void ChangeAlphabet()
Writes the training file to disk using WriteTrainFileFull, and then runs CreateDasherModel, deleting an exsiting Model if it exists.
In the event that SP_ALPHABET_ID is empty when this function is called, it is set to the default suggested by m_AlphIO.
public void ChangeColours()
If m_ColourIO is null at the time, this method will return without performing any action.
Specifically, this method retrieves the colour scheme named by SP_COLOUR_ID from m_ColourIO, and creates a new CustomColours wrapping it, finally setting m_Colours to point to the new scheme. Finally, if successful, the screen is informed of the new scheme by calling its SetColourScheme method.
public void ChangeScreen(CDasherScreen NewScreen)
If a view already exists, it is notified of the new screen.
If no view exists, one is created by a call to ChangeView.
NewScreen - New screenpublic void ChangeView()
This ought to respond to the LP_VIEW_ID parameter, but since at present there is only one, it is ignored for now.
public void GetAlphabets(java.util.ArrayList<java.lang.String> AlphabetList)
CAlphIOpublic CAlphIO.AlphInfo GetInfo(java.lang.String AlphID)
CAlphIOpublic void SetInfo(CAlphIO.AlphInfo NewInfo)
CAlphIOpublic void DeleteAlphabet(java.lang.String AlphID)
CAlphIOpublic void GetColours(java.util.ArrayList<java.lang.String> ColourList)
CColourIO
public int TrainFile(java.lang.String Filename,
int iTotalBytes,
int iOffset)
The actual training is done by TrainStream; this just creates a FileInputStream and passes it into TrainStream.
Filename - Path (absolute or relative) to file containing training text.iTotalBytes - Number of bytes to readiOffset - Offset at which to start reading
public int TrainStream(java.io.InputStream FileIn,
int iTotalBytes,
int iOffset)
LockEvents will be inserted every 1KB of data read, informing components and the interface of the progress made in reading the file.
FileIn - InputStream from which to read.iTotalBytes - Number of bytes to read.iOffset - Offset at which to start reading.
public void GetFontSizes(java.util.Collection<java.lang.Integer> FontSizes)
FontSizes - Collection to be filled with available sizespublic double GetCurCPM()
public double GetCurFPS()
public int GetAutoOffset()
CDasherViewpublic double GetNats()
CDasherModelpublic void ResetNats()
CDasherModelpublic void InvalidateContext(boolean bForceStart)
If bForceStart is true, or we received a non-empty context, the Model is fed the new Context using SetContext and is then paused.
Finally there is a mandatory screen redraw.
bForceStart - Should we rebuild the context even if none is submitted?
public void RegisterNode(int iID,
java.lang.String strLabel,
int iColour)
CDasherModel
public void ConnectNode(int iChild,
int iParent,
int iAfter)
CDasherModel
public void DisconnectNode(int iChild,
int iParent)
CDasherModel
public void SetBoolParameter(Ebp_parameters iParameter,
boolean bValue)
CSettingsStore
public void SetLongParameter(Elp_parameters iParameter,
long lValue)
CSettingsStore
public void SetStringParameter(Esp_parameters iParameter,
java.lang.String sValue)
CSettingsStorepublic boolean GetBoolParameter(Ebp_parameters iParameter)
CSettingsStorepublic long GetLongParameter(Elp_parameters iParameter)
CSettingsStorepublic java.lang.String GetStringParameter(Esp_parameters iParameter)
CSettingsStorepublic void ResetParameter(EParameters iParameter)
CSettingsStorepublic CUserLog GetUserLogPtr()
public void KeyDown(long iTime,
int iId)
Key presses signalled in this way are ignored if we have no input filter, or if BP_TRAINING is true.
Currently assigned key IDs:
The actual physical keys assigned to these functions are down to the implementation, and may be user-definable.
iTime - System time as a UNIX timestamp at which the key was pressediId - Identifier of the pressed key
public void KeyUp(long iTime,
int iId)
Key presses signalled in this way are ignored if we have no input filter, or if BP_TRAINING is true.
Currently assigned key IDs:
The actual physical keys assigned to these functions are down to the implementation, and may be user-definable.
iTime - System time as a UNIX timestamp at which the key was pressediId - Identifier of the pressed keypublic void CreateInputFilter()
If this is successful and an input filter is created, it will be Ref'd and Activated immediately.
If unsuccessful, m_InputFilter will be set to null.
If there is an existing filter, it is Deactivated and Unref'd first.
public void RegisterFactory(CModuleFactory Factory)
CModuleManagerpublic CDasherModule GetModule(long iID)
CModuleManagerpublic CDasherModule GetModuleByName(java.lang.String strName)
CModuleManagerpublic void CreateFactories()
At present this registers only Normal Control and Click Mode, but as an when others are implemented will register these also.
The same input filter may be registered repeatedly under a variety of different names if desired (so long as the filter's constructor permits a user-defined name).
This is commonly used to produce a number of different button modes which use the same filter class.
public void StartShutdown()
protected void WriteTrainFileFull()
Won't work at present, as WriteTrainFile() is stubbed.
protected void WriteTrainFilePartial()
Won't work at the moment, as WriteTrainFile() is stubbed.
public CEventHandler GetEventHandler()
public void ExternalEventHandler(CEvent Event)
By default this ignores all events; the intent is for implementations to override it if they want to either a) Pass events out to UI components which the core doesn't know about, or b) Transcribe our internal events into some other event-dispatching scheme such as Win32's message dispatching scheme.
Event - Event being signalledpublic CAlphabet GetAlphabet()
public void WriteTrainFile(java.lang.String strNewText)
This method should be implemented if a local application version of JDasher is to be implemented, and should write a file containing the user's typed text encoded as UTF-8 suitable for reading by the TrainStream routine.
strNewText - public java.io.InputStream getResourceStream(java.lang.String filename)
By default it ignores its arguments and returns null.
Overriding is optional; ordinary file I/O will still be tried before calling this method.
filename - File to be opened
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||