dasher.net
Class NetScreen

java.lang.Object
  extended by dasher.net.NetScreen
All Implemented Interfaces:
CDasherScreen

public class NetScreen
extends java.lang.Object
implements CDasherScreen

Specialised implementation of CDasherScreen which, instead of drawing its output to the screen, produces an XML document describing drawing primitives.

The XML is then serialized and output to a specified OutputStream (in the context of NetDasher typically a Socket's OutputStream) with the intent that some client application should render the drawing primitives described by the document and so reproduce the display.

The class also currently plays the role of injecting XML tags informing the client of EditEvents and of delivering some extra data in the first frame sent to a given client. In the future, these roles should ideally be moved into a seperate class such that the different classes which want to deliver XML to the client could each create an Element, and combination and serialization could be co-ordinated by some master NetDasherOutput class.

XML format

The entire document is always surrounded by

...
tags.

init: Sent only with the first produced frame, to notify the client of initial conditions. Contains the following children:

sessid: Contains the session ID associated with this newly created Dasher.

alphabet: An <alphabet/> tag is included for each alphabet Dasher knows about. The title of each is described in the tag's name attribute, and the default attribute will be 'true' for one alphabet, indicating that which Dasher is using by default. Example: %lt;alphabet name="French" default="true"/>

colour: A <colour/> tag is included for each colour scheme Dasher knows about. The title of each is described in the tag's name attribute, and the default attribute will be 'true' for one alphabet, indicating that which Dasher is using by default. Example: <colour name="Rainbow" default="true"/>

edit: Records every EditEvent which has been received by this Screen since the last frame.

The children of edit are of the form:

add: Add tags surround text added since the last frame; the tags are recorded in the XML document in the same order as the events occured. Example: <add>H</add>

remove: Have a single attribute named 'num' which indicates how many characters have been deleted. Example: <remove num="3"/>

frame: Frame tags contain a sequence of tags describing drawing primitives. The tags which may occur here are each described in the documentation for the function which may produce them, below.


Field Summary
protected  java.util.ArrayList<java.lang.String> Alphabets
          List of available alphabets
protected  java.util.ArrayList<java.lang.String> Colours
          List of available colour schemes
protected  org.w3c.dom.Document drawInstructions
          Document object which should be populated with data to be sent and which will in due time be serialized to our OutputStream.
protected  java.util.Queue<CEditEvent> editEventQueue
          Queue of EditEvents registered since the last frame was drawn.
protected  boolean firstMessage
          Flag indicating whether to output an init section with our next frame.
protected  org.w3c.dom.Element frame
          Element to which all drawing primitives should be attached.
protected  java.lang.String initialAlph
          Default alphabet name
protected  java.lang.String initialCS
          Default colour scheme
protected  CCustomColours m_ColourScheme
          Colour scheme currently in use
protected  int m_Height
          Height of this screen in pixels
protected  java.io.OutputStream m_Output
          OutputStream to which XML should be serialized at the end of the drawing cycle.
protected  int m_Width
          Width of this screen in pixels
protected  javax.xml.parsers.DocumentBuilder parser
          DocumentBuilder to be used in producing XML
protected  org.w3c.dom.Element root
          Element from which all other elements descend; named 'message' in the document schema.
protected  int sessID
          Session ID associated with the Dasher to which this Screen is linked.
protected  javax.xml.transform.Transformer XMLSerializer
          Transformer which will render the XML document as text prior to output.
 
Constructor Summary
NetScreen(int sessID, int width, int height)
          Creates a new NetScreen.
 
Method Summary
 void addEditEvent(CEditEvent event)
          Records an EditEvent to be added to the XML document during a call to Display().
protected  void addEditEvents()
          Adds all EditEvents recorded since the last frame to the XML document, in the manner described in the class summary.
 void Blank()
          Signals the start of a new frame; see CDasherScreen for the general contract of this method.
 void Display()
          Calls addEditEvents before serializing the XML document produced during the drawing cycle and writing it to m_Output, (an OutputStream specified by the setOutput method).
 void DrawCircle(int iCX, int iCY, int iR, int iColour, boolean bFill)
          Adds a tag of the form <circle centrex="..." centrey="..." radius="..." fill="..." colour="..."/> to the Frame tag of this document.
 void DrawRectangle(int x1, int y1, int x2, int y2, int Color, int iOutlineColour, EColorSchemes ColorScheme, boolean bDrawOutline, boolean bFill, int iThickness)
          Adds a tag of the form <rect x="..." y="..." w="..." h="..." colour="..." olcolour="..." thickness="..." fill="..." drawoutline="..."/> to the Frame tag of this document.
 void DrawString(java.lang.String string, int x1, int y1, long Size)
          Adds a tag of the form <string size="..." x="..." y="...">The String</string> to the Frame tag of this document.
protected  java.lang.String getColour(int iColour)
          Transforms a Dasher colour identifier into an HTML-style #RRGGBB expression describing said colour.
 int GetHeight()
          Gets the height, and hence maximum Y screen co-ordinate.
 int GetWidth()
          Gets the width, and hence maximum X screen co-ordinate.
 void Polygon(CDasherView.Point[] Points, int Number, int Color)
          See Polygon(CDasherView.Point[], int, int, int, boolean)
 void Polygon(CDasherView.Point[] Points, int Number, int Color, int iWidth)
          See Polygon(CDasherView.Point[], int, int, int, boolean)
protected  void Polygon(CDasherView.Point[] Points, int Number, int Color, int iWidth, boolean fill)
          Adds a polygon to the XML document in the following format:
 void Polyline(CDasherView.Point[] Points, int Number, int iWidth)
          See Polygon(CDasherView.Point[], int, int, int, boolean)
 void Polyline(CDasherView.Point[] Points, int Number, int iWidth, int Colour)
          See Polygon(CDasherView.Point[], int, int, int, boolean)
 void SendMarker(int iMarker)
          Stub.
 void setAlphabets(java.util.ArrayList<java.lang.String> Alphs)
          Sets the list of available alphabets to be recorded during the production of the <init> section produced for the first frame.
 void setColours(java.util.ArrayList<java.lang.String> Cols)
          Sets the list of available colour schemes to be recorded during the production of the <init> section produced for the first frame.
 void SetColourScheme(CCustomColours ColourScheme)
          Sets the colour scheme to use
 void setInitialAlph(java.lang.String alph)
          Sets the default alphabet to be reported when this Screen draws its first frame.
 void setInitialCS(java.lang.String CS)
          Sets the default colour scheme to be reported when this Screen draws its first frame.
 void setOutput(java.io.OutputStream out)
          Sets the output stream to which XML should be serialized.
 CDasherView.Point TextSize(java.lang.String string, int Size)
          Determines / guesses the size of a given string as drawn on this screen.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

firstMessage

protected boolean firstMessage
Flag indicating whether to output an init section with our next frame.


drawInstructions

protected org.w3c.dom.Document drawInstructions
Document object which should be populated with data to be sent and which will in due time be serialized to our OutputStream.


root

protected org.w3c.dom.Element root
Element from which all other elements descend; named 'message' in the document schema.


frame

protected org.w3c.dom.Element frame
Element to which all drawing primitives should be attached.


m_ColourScheme

protected CCustomColours m_ColourScheme
Colour scheme currently in use


m_Output

protected java.io.OutputStream m_Output
OutputStream to which XML should be serialized at the end of the drawing cycle.


sessID

protected int sessID
Session ID associated with the Dasher to which this Screen is linked.


editEventQueue

protected java.util.Queue<CEditEvent> editEventQueue
Queue of EditEvents registered since the last frame was drawn.


Alphabets

protected java.util.ArrayList<java.lang.String> Alphabets
List of available alphabets


Colours

protected java.util.ArrayList<java.lang.String> Colours
List of available colour schemes


initialCS

protected java.lang.String initialCS
Default colour scheme


initialAlph

protected java.lang.String initialAlph
Default alphabet name


parser

protected javax.xml.parsers.DocumentBuilder parser
DocumentBuilder to be used in producing XML


XMLSerializer

protected javax.xml.transform.Transformer XMLSerializer
Transformer which will render the XML document as text prior to output.


m_Width

protected int m_Width
Width of this screen in pixels


m_Height

protected int m_Height
Height of this screen in pixels

Constructor Detail

NetScreen

public NetScreen(int sessID,
                 int width,
                 int height)
Creates a new NetScreen.

Sets up a DocumentBuilder and Transformer for the production of XML and saves the height, width and session ID associated with this screen.

Parameters:
sessID - Session ID
width - Screen width in pixels
height - Screen height in pixels
Method Detail

Blank

public void Blank()
Signals the start of a new frame; see CDasherScreen for the general contract of this method.

In this specific case, a new Document is created and stored in drawInstructions, and required Elements message and frame are created and stored in root and frame respectively for use by other means.

Finally, if the firstMessage flag is true, the <init> section is created as described above.

Specified by:
Blank in interface CDasherScreen

Display

public void Display()
Calls addEditEvents before serializing the XML document produced during the drawing cycle and writing it to m_Output, (an OutputStream specified by the setOutput method).

For the general contract of this method, see CDasherScreen.

Specified by:
Display in interface CDasherScreen

setAlphabets

public void setAlphabets(java.util.ArrayList<java.lang.String> Alphs)
Sets the list of available alphabets to be recorded during the production of the <init> section produced for the first frame.

Parameters:
Alphs - List of available alphabets

setColours

public void setColours(java.util.ArrayList<java.lang.String> Cols)
Sets the list of available colour schemes to be recorded during the production of the <init> section produced for the first frame.

Parameters:
Cols - List of available colour schemes

addEditEvent

public void addEditEvent(CEditEvent event)
Records an EditEvent to be added to the XML document during a call to Display().

Parameters:
event - New EditEvent

addEditEvents

protected void addEditEvents()
Adds all EditEvents recorded since the last frame to the XML document, in the manner described in the class summary.


DrawCircle

public void DrawCircle(int iCX,
                       int iCY,
                       int iR,
                       int iColour,
                       boolean bFill)
Adds a tag of the form <circle centrex="..." centrey="..." radius="..." fill="..." colour="..."/> to the Frame tag of this document.

The colour attributes are recorded in standard #RRGGBB format.

Specified by:
DrawCircle in interface CDasherScreen
Parameters:
iCX - X co-ordinate of the centre
iCY - Y co-ordinate of the centre
iR - Radius in pixels
iColour - Colour number
bFill - Fill or outline?

DrawRectangle

public void DrawRectangle(int x1,
                          int y1,
                          int x2,
                          int y2,
                          int Color,
                          int iOutlineColour,
                          EColorSchemes ColorScheme,
                          boolean bDrawOutline,
                          boolean bFill,
                          int iThickness)
Adds a tag of the form <rect x="..." y="..." w="..." h="..." colour="..." olcolour="..." thickness="..." fill="..." drawoutline="..."/> to the Frame tag of this document.

The colour attributes are recorded in standard #RRGGBB format.

Specified by:
DrawRectangle in interface CDasherScreen
Parameters:
x1 - top left of rectangle (x coordinate)
y1 - top left corner of rectangle (y coordinate)
x2 - bottom right of rectangle (x coordinate)
y2 - bottom right of rectangle (y coordinate)
Color - the colour to be used (numeric)
ColorScheme - Which colourscheme is to be used
bDrawOutline - Whether to draw an outline or not
bFill - Whether to fill or not
iThickness - Line thickness for outline

DrawString

public void DrawString(java.lang.String string,
                       int x1,
                       int y1,
                       long Size)
Adds a tag of the form <string size="..." x="..." y="...">The String</string> to the Frame tag of this document.

The co-ordinates describe the top-left corner of a bounding rectangle.

Specified by:
DrawString in interface CDasherScreen
Parameters:
string - String to draw
x1 - Top-left hand corner x co-ordinate
y1 - Top-left hand corner y co-ordinate
Size - Font size in points

GetHeight

public int GetHeight()
Description copied from interface: CDasherScreen
Gets the height, and hence maximum Y screen co-ordinate.

Specified by:
GetHeight in interface CDasherScreen
Returns:
height

GetWidth

public int GetWidth()
Description copied from interface: CDasherScreen
Gets the width, and hence maximum X screen co-ordinate.

Specified by:
GetWidth in interface CDasherScreen
Returns:
width

Polygon

public void Polygon(CDasherView.Point[] Points,
                    int Number,
                    int Color,
                    int iWidth)
See Polygon(CDasherView.Point[], int, int, int, boolean)

Specified by:
Polygon in interface CDasherScreen
Parameters:
Points - array of points defining the edge of the polygon
Number - number of points in the array
Color - colour of the polygon (numeric)
iWidth - Width of the polygon border to draw

Polygon

protected void Polygon(CDasherView.Point[] Points,
                       int Number,
                       int Color,
                       int iWidth,
                       boolean fill)
Adds a polygon to the XML document in the following format:

<poly colour="..." fill="..." thickness="..."> <point x="..." y="..."/> <point x="..." y="..."/> ... </poly>

Parameters:
Points - Array of Points constituting the polygon
Number - Number of points in the polygon
Color - Outline colour
iWidth - Outline width
fill - Fill colour

Polygon

public void Polygon(CDasherView.Point[] Points,
                    int Number,
                    int Color)
See Polygon(CDasherView.Point[], int, int, int, boolean)

Specified by:
Polygon in interface CDasherScreen
Parameters:
Points - array of points defining the edge of the polygon
Number - number of points in the array
Color - colour of the polygon (numeric)

Polyline

public void Polyline(CDasherView.Point[] Points,
                     int Number,
                     int iWidth,
                     int Colour)
See Polygon(CDasherView.Point[], int, int, int, boolean)

Specified by:
Polyline in interface CDasherScreen
Parameters:
Points - Array of Points describing the vertices of the line.
Number - Number of points
iWidth - Line width
Colour - Colour number

Polyline

public void Polyline(CDasherView.Point[] Points,
                     int Number,
                     int iWidth)
See Polygon(CDasherView.Point[], int, int, int, boolean)

Specified by:
Polyline in interface CDasherScreen
Parameters:
Points - Array of Points describing the vertices of the line.
Number - Number of points
iWidth - Line width

SendMarker

public void SendMarker(int iMarker)
Stub. For the general contract of this method, see CDasherScreen.

Specified by:
SendMarker in interface CDasherScreen
Parameters:
iMarker - Marker number

SetColourScheme

public void SetColourScheme(CCustomColours ColourScheme)
Description copied from interface: CDasherScreen
Sets the colour scheme to use

Specified by:
SetColourScheme in interface CDasherScreen
Parameters:
ColourScheme - New colour scheme

TextSize

public CDasherView.Point TextSize(java.lang.String string,
                                  int Size)
Description copied from interface: CDasherScreen
Determines / guesses the size of a given string as drawn on this screen.

This is used in determining how much to displace other drawn strings in order to prevent them from overlapping.

This must be carried out by the screen because only the actual drawing surface can know how fonts appear when rendered.

Specified by:
TextSize in interface CDasherScreen
Parameters:
string - String whose size we wish to determine
Size - Font size in points
Returns:
Point specifying the width and height of this string.

getColour

protected java.lang.String getColour(int iColour)
Transforms a Dasher colour identifier into an HTML-style #RRGGBB expression describing said colour.

Parameters:
iColour - Colour index
Returns:
HTML colour

setOutput

public void setOutput(java.io.OutputStream out)
Sets the output stream to which XML should be serialized.

Typically this will be set prior to calling NewFrame, but it will take effect if set at any time before Display() is called.

Parameters:
out - OutputStream to which the next frame's XML should be written

setInitialAlph

public void setInitialAlph(java.lang.String alph)
Sets the default alphabet to be reported when this Screen draws its first frame.

Parameters:
alph - Default alphabet

setInitialCS

public void setInitialCS(java.lang.String CS)
Sets the default colour scheme to be reported when this Screen draws its first frame.

Parameters:
CS - Default colour scheme