Redesign of “My Art Gallery”

My Art Gallery (http://my-art-gallery.co.uk/) is my fathers online art gallery which features most of his artwork. The website also includes a variety of downloads including backgrounds, 3D models, textures, etc. which people can use in their own artwork. I originally created this website in 2006 using ASP.NET in conjunction with a MS-SQL database which has served well for 4 years.

After 4 years the website began to look a little dated and so it felt necessary to bring it up to date both visually and functionally. The web has changed significantly and nowadays people tend to expect facilities like RSS, comments and track-backs. Read more of this post

UML Simpler with Cadifra

Cadifra is an excellent UML editor which makes designing with UML a breeze. Cadifra is great for illustrating concepts in technical reports, but gains its real purpose during the design process where ideas change and evolve rapidly (especially when working with other team members). Cadifra makes it easy and very quick to change diagrams in this fashion, and very neatly too.

Cadifra supports Class, Object, Use Case, Sequence and State diagrams. Read more of this post

J2ME: Alert followed by Alert

I have been working on a J2ME application. There is an instance where a message box appears to confirm an action with the user, if the user confirms the action then a subsequent alert may be shown. Whilst in theory this should have been straightforward the application just kept throwing an IllegalArgumentException.

In the API documentation for J2ME I found that the Display.setCurrent(alert, nextDisplayable) function will throw such an exception when nextDisplayable is an Alert instance. However, I was not using this function. The alert was being displayed using Display.setCurrent(displayable), and upon selecting “Confirm” was simply displaying another alert again with Display.setCurrent(displayable).

With thanks to James Mernin’s blog (Alert after Alert in J2ME) I found that this is in fact a result of the same limitation within J2ME. For my purposes I found that the simplest solution was to create a blank canvas, and upon the first paint event switch to the intended alert. This essentially breaks the chain into Alert -> Canvas -> Alert.
Read more of this post

Problems with the JMUnit TestSuite Class

I attempted to use the ‘JMUnit’ unit testing library that is shipped with NetBeans for the first time today. I created a couple of simple TestCase classes and a TestSuite that combines each of these. However, every time I attempted to load the test suite I was presented with the following exception:

result 0: first.AdderTest
java.lang.SecurityException: MIDlet not constructed by createMIDlet.
        at com.sun.midp.midlet.MIDletStateHandler.newMIDletPeer(), bci=24
        at javax.microedition.midlet.MIDlet.(), bci=9
        at jmunit.framework.cldc10.Assertion.(), bci=1
        at jmunit.framework.cldc10.Test.(), bci=1
        at jmunit.framework.cldc10.TestCase.(), bci=2
        at first.AdderTest.(), bci=4
        at java.lang.Class.newInstance(), bci=0
        at jmunit.framework.cldc10.TestSuite.(), bci=57
        at java.lang.Class.newInstance(), bci=0
        at com.sun.midp.main.CldcMIDletLoader.newInstance(), bci=46
        at com.sun.midp.midlet.MIDletStateHandler.createMIDlet(), bci=66
        at com.sun.midp.midlet.MIDletStateHandler.createAndRegisterMIDlet(), bci=17
        at com.sun.midp.midlet.MIDletStateHandler.startSuite(), bci=27
        at com.sun.midp.main.AbstractMIDletSuiteLoader.startSuite(), bci=52
        at com.sun.midp.main.CldcMIDletSuiteLoader.startSuite(), bci=8
        at com.sun.midp.main.AbstractMIDletSuiteLoader.runMIDletSuite(), bci=161
        at com.sun.midp.main.AppIsolateMIDletSuiteLoader.main(), bci=26

Read more of this post

Simplified ‘Display’ Management for J2ME

Switching between displayable objects such as canvases and alerts can become tricky when working on more complex applications. Code can easily become cluttered with excess ‘display’ and “midlet” references, despite that there is usually only one unique display instance.

This mess can be cleaned up by creating some static helper methods which provide instant access to the display instance without the need to maintain either midlet or display references.

public final class DisplayManager {
   // The one and only display object.
   private static Display display;

   // Get the one and only display object.
   public static final Display getDisplay() { return display; }

   // A one off call is required to prepare the display manager.
   public static final void initialize(Display display) {
      current = (DisplayManager.display = display).getCurrent();
   }
}

Read more of this post

PrototypeJS Extension: Namespaces for JavaScript

Namespaces are an extremely useful tool when working with numerous classes, functions or even objects in many programming languages. They allow the developer to group these entities in an intuitive way to facilitate readability.

More importantly, namespaces are a mechanism which help to avoid clashing occurrences of unrelated objects which share the same name. This can easily happen when utilizing sources that were developed by separate parties.

A while back I wrote a utility method to ease the support of namespaces within JavaScript. This utility method uses features from the PrototypeJS framework.

Read more of this post

Enhancement on Soft-Key Detection

With many thanks to Graham over at the Nokia Discussion forums I came across an interesting Wiki article (Platform independent key events processing) which provides a class that tries to determine common non-standard keycodes for a variety of handsets. The second handset that I tested was an LG KS360, unfortunately this detection class was unable to detect the soft key buttons.

I have combined my welcome screen based soft-key detection into that class as a fail-safe, and this seems to be working great. So, where possible the correct keycodes are detected by working out the device vendor, and then where all else fails, accept the first non-standard keycode that is returned from the welcome screen for the left soft-key.

I have also added a SOFTKEY_GUESSED field which indicates if the left soft-key value was guessed. If it was, then you can decide whether or not to allow other non-standard keys to represent the right soft-key. You might decide against guessing the right soft-key in more critical scenarios where data could potentially be lost by pressing another unrelated button on the keypad.

The combination of these two techniques seems to provide a much better solution.

Generic soft key detection in J2ME

As many of you are aware, the soft key buttons on a mobile phone are general purpose buttons that are reused over and over again. On most handsets there are two of these directly beneath the screen (one on the left, and one on the right).

In a recent project I needed to be able to detect when the left and right soft keys were being pressed, but unfortunately, J2ME does not define a standard key code. Instead it is up to the developer to specify different codes for all of the different phones in their target audience.

Two solutions came to mind:

  1. Compile the application for each target handset (perhaps overkill given that this be the only difference).
  2. Get the user to specify which button is which (even if they do not realize this!).

Read more of this post

XPointer Framework for XSLT 2.0

In a recent project I found myself needing more flexibility when cross-referencing XML content during XSLT transformations. The XSLT 2.0 specification (as implemented by Michael Kay) only includes shorthand XPointers. So this seemed a good opportunity to write a more complete implementation of the XPointer Framework for Michael Kay’s fantastic Saxon processor.

Essentially, XPointer allows one to reference a fragment of a resource (as opposed to the entire resource):

<!-- Shorthand XPointer: Locate a customer using the @xml:id attribute. -->
<order customer="customers.xml#cust001"/>
<!-- Element Scheme: First customer in an element where @xml:id="customers". -->
<order customer="customers.xml#element(customers/1)"/>

My implementation of this includes support for the standard xmlns() and element() schemes, and additionally the xmlns-local(), xpath1() and xpath2() schemes. This implementation, however, does not yet include the xpointer() scheme.

Additional schemes can be implemented by providing a custom template. The template will be invoked automatically by the XPointer framework stylesheet when the scheme is detected in a URI upon lookup. Custom schemes should be qualified with a namespace so as to avoid conflicts unless implementing a standardized scheme.

I have made the stylesheet (and some examples) freely available under the BSD license.

Check out http://www.rotorz.com/xml/2009/XPointer for more information and downloads.