Sunday, March 4, 2007

Meanwhile, back in the Source Code...

Aufero's WizardHandler and Dynamic Screens is one of the components in Aufero that is very much stand-alone so I decided that I'd slap an LGPL license on it and share it. Besides, I needed a break from Visual Studio.

For the uninitiated, LGPL is a license that permits you to use the 'library' as is, but if you modify the code to suit you you have to share it, and of course, you have to give credits where credits are due. In other words, a very fair license: You take some and give some.

I don't have a host where I can store these files, so you will have to use copy and paste from the link at the bottom. If you would like to host it, throw an email my way. And of course, suggestions and improvements (in source code or not) are most welcome (aufero.vmc@gmail.com).

And I can safely say that this was the last fucking time I post source code using Blogger. Goddamn. This was a painful experience.


This 'library'
The library comes in the shape of C# source-code and Media Center markup where the former is the model and latter is the view. It consists of four parts: Handler, Screen, Widgets and the related MCML. I will outline these in more detail below.

I wrote this initially to handle configuration and setup within Aufero, so it contains all the logic needed by a configuration handler. In fact, in Aufero's case it IS the configuration handler. Furthermore it will only use one "MCML screen" and "modify" it as it needs by doing some trickery. Perhaps not really trickery, but it's not pretty either (oh, it sure beats in-line code).

I have tried removing all references to Aufero components but some might have slipped through, in which case you will just have to weed that out or just put in your own replacement. Also, I have left the MCML widgets intentionally bland (or ugly if you wish), you will want your own unique look on those things anyway. If you create some nice looking widgets, please share them! We could all use it!


The class diagram
Before we continue I'll be rude and throw a class diagram at you so that you can see how it's all laid out, with a bit of luck you don't have to read further once you see it (!)


The WizardHandler
A WizardHandler is a container for a series of dynamic screens, it handles navigation within the set of screens. If you do not want a Wizard to show up in your standard Media Center navigation you will have to create your own Session to see to it that it doesn't put it in the History.

A simple implementation of your own WizardHandler could be:

public class AuferoSetupHandler : WizardHandler
{
  public AuferoSetupHandler(int startScreen)
    : base(startScreen)
  {
    NavigationEvent += new NavigationHandler(ButtonClicked);
    MCMLview = new Uri("resx://Aufero/Aufero.Resources/SetupScreens#Default");
    Screens.Add(new SetupScreen1(0, this));
  }
}

As you can see, it's a straightforward class that:
  1. Tells WizardHandler that it wants to receive navigation events.
  2. Tells WizardHandler where to find the MCML view we are based on.
  3. Adds a set of screens to a the set (only one in this case).
Generally I don't think they will get much more complicated than this, but your mileage may vary.


The Dynamic Screens (aka Screen)
Well, the comment in the source code says "A dynamic screen, inherit and use.". This pretty much sums it up. But to expand a bit on it: A screen is a container for a set of widgets (text, checkboxes, buttons...), it will help you with implementing scrollable areas for widgets and similar on the View side of things as well. A bit of footwork is done in MCML if you look at SetupScreens.mcml.


Your Customized Screens
They inherit Screen (see Dynamic Screens above), this is where you will do the work
on what should be presented on your screens. When passing screens to your UI's, you'll find the interface IScreen your best friend.

A simple customized screen could be:

public class SetupScreen1 : Screen
{
  public SetupScreen1(int sequenceId, WizardHandler handler)
    : base(sequenceId, handler)
  {
    TextArticle ta = new TextArticle();
    ta.Headline = "Welcome to Aufero!";
    ta.Body = "Aufero is a software package that helps " +
      "you set up, organize and get " +
      "more information about your media.\n";

    base.MainText = ta;
    Widgets.Add(new CheckboxWidget("mycheckbox", "Click me!"));
    base.NavigationButtons.Add("Cancel");
    base.NavigationButtons.Add("Next");
  }
}

The above snippet just adds a title, a body, a checkbox and two navigation buttons
to the screen. I use something similar as a first screen in Aufero's first-time
setup.


The Visual Elements (aka Widgets)
These are the key to the whole thing, a widget can be a textbox, checkbox, just a text element and similar. I have only included four different widgets in this example (read: I have only written four Wizard Widgets for Aufero so far). The widgets are contained by a Screen as was demonstrated earlier. They will be presented in the order they were inserted into the screen.


The View (aka MCML)
This is split up into two different files, one for the actual screen that is presented to the user and one file that contains all the helper UI's like widgets and similar for screens. I left them ugly because my design skills are less than good.


On The Ending Note
I had to hurry up a bit in the end here so perhaps I didn't elaborate enough on certain aspects, but ask away if something is not clear. For the code go to: http://aufero.informe.com/ then click on Source Code.

I'll let the Source Code say the rest. Have fun.

1 comment:

Anonymous said...

Good for people to know.