Implementation Decisions for the Display Class
The previous post described the proposed Display class, which is intended to wrap a stable layer of code around small form factor displays which will be used in Arago and similar products. It only makes sense to have this class easily extendable, in some way, for new displays incorporated into future designs. This will be accomplished through the use of Java .properties files, wherein information specific to each display will be stored in its own file — shades of termcap! By convention, the unique string of characters associated with the display will form the root of the name and will be suffixed by .properties of course. For example, the GLK24064-16-1U currently being use would have a properties file called GLK24064-16-1U.properties. These files will all be collected up in one directory, which for the time being is located within the Intellog project, in the directory src/intellog/display.
An article in JavaWorld by Vladimir Roubtsov was the basis of the implementation strategy, wherein Java’s ClassLoader is used to find the resource — that is, the .properties file. It subsequently uses InputStream to populate an instance of the Properties class. As Vladimir says in his article, this is the preferred approach because "classloaders essentially act as a layer of abstraction between a resource name and its actual location on disk". In other words, it will make for reduced cost-of-ownership down the road — easier packaging and deployment, for instance. In order to distill it to its essence, five lines were extracted from the code in Vladimir’s article, and refactored into a Util.loadProperties(string) method. This takes the name of the resource (eg. GLK24064-16-1U.properties) as input, and returns an instance of Properties populated with all of the properties found in the file
It then became a matter of establishing some conventions for the content of each .properties file, which didn’t have to be anything fancy. The properties are generally named to reflect the methods to which they are related. For instance, the line GLK24064-16-1U.properties relating to the display’s brightness, not surprisingly, uses a property named brightness, which reflects the setBrightness(int) method. Currently, properties are lumped into two categories; specifications, which identify the characteristics of the display, and control sequences, which contain the strings of control characters which produce the desired effect. With the latter, it’s tempting to try and support every conceivable format for the control information, but the decision was made to use just one — the 0x00 format, separated by spaces.
Having cracked the problem of how to store the display-specific information in a .properties file, it was an obvious choice to use the same approach to store the Arago-specific properties as well. These types of properties are going to be stored in arago.properties, and its content is retrieved using the same Until.loadProperties() method described above. Also, one final note — to drastically streamline the code, it’s assumed all of these properties files will be read-only. If they need to be maintained, that will be done so by hand, using any handy text editor.
Code Shavings Given this is the first real Java code to get cut in a while, it’s still uncertain exactly what part of it is general in nature, and what part is specific to the Arago. To reflect this, two Java projects were created in Eclipse; Intellog, for code with general application, and Arago for code specific to, you guessed it, the Arago. ♦ The Java Tutorials continued to be a very useful resource, and the unit entitled Properties was particularly useful in working through the decision making process described above. ♦ Instinct (and little else) dictated XML would be the correct format in which to store the display-specific information. However, Bart Busschots makes a pretty good case for going with the Java .properties flow and using the very simple format it specifies. And truth be told, there is a very easy way to convert them to XML in the future, if necessary.
Posted on 28th August 2009
Under: Arago, Developers' Journal | No Comments »