dasher
Class CColourIO

java.lang.Object
  extended by dasher.CColourIO

public class CColourIO
extends java.lang.Object

Responsible for reading a given list of XML files, extracting colour scheme information, and creating a list of ColourInfo objects for each.

Further, after doing so, responsible for returning a ColourInfo object corresponding to a given alphabet name, and of giving a full list of available colour schemes.


Nested Class Summary
static class CColourIO.ColourInfo
          Simple struct which represents a colour scheme.
 
Field Summary
protected  java.util.HashMap<java.lang.String,CColourIO.ColourInfo> Colours
          Map from colour scheme names to their ColourInfo objects.
protected  java.util.ArrayList<java.lang.String> Filenames
          Files which are to be parsed.
 boolean LoadMutable
          Flag indicating whether or not the current colour scheme may be modified.
 CDasherInterfaceBase m_Interface
          Interface which will be used for Applet style I/O.
protected  javax.xml.parsers.SAXParser parser
          SAXParser used to read XML files.
protected  java.lang.String SystemLocation
          The current system data location, for locating DTDs.
protected  java.lang.String UserLocation
          The current user data location, for locating DTDs.
 
Constructor Summary
CColourIO(java.lang.String SysLoc, java.lang.String UserLoc, java.util.ArrayList<java.lang.String> Fnames, CDasherInterfaceBase dib)
          Sole constructor.
 
Method Summary
protected  void CreateDefault()
          Creates and stores a default colour scheme, named simply Default.
 void Delete(java.lang.String ColourID)
          Removes a colour scheme by name.
 void GetColours(java.util.Collection<java.lang.String> ColourList)
          Fills a given Collection with the names of all available colour schemes.
 CColourIO.ColourInfo GetInfo(java.lang.String ColourID)
          Retrieves the ColourInfo object associated with a given colour scheme.
 void ParseFile(java.lang.String filename)
          Parse a named XML file.
 void Save(java.lang.String name)
          Stub method.
 void SetInfo(CColourIO.ColourInfo NewInfo)
          Adds a ColourInfo object to the list of those available.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SystemLocation

protected java.lang.String SystemLocation
The current system data location, for locating DTDs.


UserLocation

protected java.lang.String UserLocation
The current user data location, for locating DTDs.


Colours

protected java.util.HashMap<java.lang.String,CColourIO.ColourInfo> Colours
Map from colour scheme names to their ColourInfo objects.


Filenames

protected java.util.ArrayList<java.lang.String> Filenames
Files which are to be parsed.


LoadMutable

public boolean LoadMutable
Flag indicating whether or not the current colour scheme may be modified.


m_Interface

public CDasherInterfaceBase m_Interface
Interface which will be used for Applet style I/O.


parser

protected javax.xml.parsers.SAXParser parser
SAXParser used to read XML files.

Constructor Detail

CColourIO

public CColourIO(java.lang.String SysLoc,
                 java.lang.String UserLoc,
                 java.util.ArrayList<java.lang.String> Fnames,
                 CDasherInterfaceBase dib)
Sole constructor. Parses a given list of XML files; once the constructor terminates, the class is ready to give a list of available colour schemes and return ColourInfo objects requested by name.

Parameters:
SysLoc - System data location to search for DTD files.
UserLoc - User data location to search for DTD files.
Fnames - List of files to parse.
dib - Interface against which we can perform applet-style IO. Optional; if null, applet-style IO will not be attempted.
Method Detail

ParseFile

public void ParseFile(java.lang.String filename)
Parse a named XML file. Colour-schemes found, if any, will be imported and may be enumerated with GetColours or retrieved using GetInfo. If the specified XML file cannot be read, the method prints the exception raised but does not throw an exception.

This method will attempt to retrieve the file first by ordinary file I/O, and then if this fails, will attempt to retrieve a resource stream, allowing it to find XML files stored in a JAR.

Parameters:
filename - Relative or absolute path to the file to be parsed.

GetColours

public void GetColours(java.util.Collection<java.lang.String> ColourList)
Fills a given Collection with the names of all available colour schemes.

Colour schemes can be made available by being parsed from an XML file by way of the ParseFile method (or through the constructor), or by the manual creation of a ColourInfo object which must then be saved using SetInfo.

Parameters:
ColourList - Collection to be filled with available colours.

GetInfo

public CColourIO.ColourInfo GetInfo(java.lang.String ColourID)
Retrieves the ColourInfo object associated with a given colour scheme.

If the specified name cannot be found, the Default scheme will be retrieved. To avoid this happening, make sure that only schemes enumerated by GetColours are requested.

Schemes' names may consist of any Unicode character in the Basic Multilingual Plane.

Parameters:
ColourID - Name of the colour scheme to retrieve.
Returns:
ColourInfo object representing the named scheme, or the Default if this is not possible.

SetInfo

public void SetInfo(CColourIO.ColourInfo NewInfo)
Adds a ColourInfo object to the list of those available. At present, schemes cannot be manually stored in Dasher, but this may change in the future if user-defined schemes become a possibility.

Parameters:
NewInfo - Colour scheme to save. Must not be null.

Delete

public void Delete(java.lang.String ColourID)
Removes a colour scheme by name. This removes the stated scheme from the list of those available; it will no longer be returned by GetColours or be retrievable by GetInfo.

Parameters:
ColourID - Name of the scheme to remove. If the given name does not exist the method will return without error.

Save

public void Save(java.lang.String name)
Stub method. In the future, this may save a given scheme as an XML file, or in some other format. This should be implemented if user-defined or mutable colour schemes are implemented.

The class must already know about the scheme to be able to save it.

Parameters:
name - Name of the scheme to save.

CreateDefault

protected void CreateDefault()
Creates and stores a default colour scheme, named simply Default. This is the scheme which will be returned in the event of a non-existent scheme being requested, and can always be assumed to be available.