Examination of a WPF Business Application

July 7th, 2008

Watch this video for a demo of a business application written in WPF. It’s great to see such demos; we know WPF is being used but actual demos are pretty rare.

In the demo, we can see the power of WPF’s ListBox. Like Billy Hollis, the demo narrator and one of the developers on the project, mentions the flexibility available in the WPF ListBox control is not available in most other GUI toolkits. Swing’s ability to use any Component as a list item renderer is pretty powerful but WPF’s ListBox has more options.

It’s great that WPF is working for them, but to be honest, aside from the animations, rotated items, and special ListBox’s, I didn’t see anything that couldn’t be done with Swing a few years ago. Swing doesn’t have databinding built-in but keeping two components in synch as shown in the video is pretty simple using property change events. Back in 2001, I had a similar requirement in a Swing application I was building and the UI portion of the code was simple. What was much more complex was building an object registry to ensure that there was only one client-side instance of each business logic. Billy also stated the dirty logic checking was something that was unique to WPF. I’m not sure what he meant by that because as far as I know WPF contains nothing for dirty object handling; it must be all written by hand. With an object registry in place, it’s no big deal to look for all objects still marked dirty.

For the special ListBox’s Billy demonstrated, Swing probably will stumble a bit. 4 or 5 years ago Scott Violet and/or Shannon Hickey demonstrated a customized JList with animation and rotating elements, but I think they said that it was pretty complex and required hacking Swing’s internals. More than likely, one would be better off building the special ListBox’s from scratch.

The demo’d UI looks pretty slick, but I didn’t see anything to help people with disabilities use the application. Nor did I see any accelerator or keyboard shortcut support.

How to tell when an open-source project is dead

June 11th, 2008

You know when an open-source project is dead when the forums consist solely of porn spam. At work, we use Anthem.Net and I’m looking into a problem that might be related to Anthem. I wanted to see if anybody else was complaining about a similar problem before diving in. Checking the Anthem General ASP.NET Discussion forum, all I see post after post for week after week is obvious porn spam. Clearly Anthem.NET is dead. After 2006, the real posts drop off. Working with the technology of yesteryear is one of the cool perks of this company. The Java side of the company is using Java 1.4, Turbine, and Velocity.

NASDAQ Market Replay

June 11th, 2008

InfoQ has a case study today on the NASDAQ Market Replay application. It allows traders and brokers to explore past market activities and examine, graphically, price fluctuations. There is a demo of the application on the NASDAQ website. This is interesting to me as I am still trying to determine what type of rich application behavior people are looking for.

In this application, “rich” essentially means interactive data graphing with the ability to zoom in for more detail. I hope I’m not overlooking something or oversimplifying the application, but that is what I gleaned from the NASDAQ website and demo.

IMHO, this is not a very good example of RIA. The UI is nothing extraordinary and could be implemented with technology cheaply available 20 years ago (e.g. Macintoshes). Obviously more difficult is obtaining the significant amount of trading data. Probably 15 years ago, brokerages could store this amount of data and make it available to in-house applications. Large brokerages probably had similar applications to this one implemented in X Windows. Only in the last 6 or so years have broadband network capacities been so common that this service could be offered to everyone over the Internet.

RIA Job Openings on the Rise in Selected Theatres

June 10th, 2008

Pete Brown talks today about RIA Job Openings on the Rise. It is true there appear to be plenty of RIA jobs in New York, Chicago, San Fransisco, London, and Redmond. But outside of those locales pretty much nothing. I know from my numerous Swing job searches over the years that Swing is doing quite well in financial centers. It looks like these same centers are interested in all RIA technology. Someone else mentioned this too recently in a WPF blog.

By the way, it’s interesting to replace JavaFX with Swing in the trends graph.


"adobe flex", silverlight, swing, wpf Job Trends graph

"adobe flex", silverlight, swing, wpf Job Trends "adobe flex" jobs - silverlight jobs - swing jobs - wpf jobs

A WPF HorizontalStack Panel

May 29th, 2008

WPF’s StackPanel is very handy and I use it a lot. Usually I want a uniform gap between the child elements. I can do that with a Margin, but doing so feels clumsy and obscures the intent. I prefer to just set a gap width on the panel and let it insert the gap between children. That’s what I did in my Swing library Jurvis with JvColumnFillLayout. That layout manager also had the extra feature of being able to select one child to receive all extra space. Very simple concept but I used that feature many times.

Y’all can probably guess where I’m going with this. Yep, I “ported” JvColumnFillLayout to WPF. Well, actually I created a horizontal version of this layout manager since I seem lately to be using more horizontal StackPanels than vertical ones.

Here’s a screenshot of my test application:





The last two “Smoke on the water” lines show the “fill” feature where first “on” is the fill element and then “the” is the fill element.

The complete project is available here.

It’s used like this:

<local:HorizontalStack ItemGap=”10″ Background=”Plum”>

    <TextBlock Text=”Smoke”/>

    <TextBlock Text=”On” local:HorizontalStack.Fill=”True” Background=”CadetBlue”/>

    <TextBlock Text=”The”/>

    <TextBlock Text=”Water”/>

</local:HorizontalStack>

Bring Back the Thick Client

May 22nd, 2008

Over ten years ago many internal thick client applications were replaced with browser-based applications. The reason for this change was because of the effort of keeping client installations up to date. System administrators would have to go around from workstation to workstation and manually perform upgrades.

With browser-based applications, client installations went away. There was a cost though. Developers had to give up their tools. Tools like PowerBuilder or even Visual Basic that made it easy to create and populate screens didn’t work with browsers. Instead, developers had to create their screens with Perl and do all the database querying and data binding by hand. Much later, more advanced tools like ASP.NET and Ruby on Rails reduced the effort but earlier productivity levels were not restored.

Users paid a cost too in terms of usability. For the first several years, browser-based applications had user interfaces that were actually more simplistic than the Curses and green screen interfaces of the 70’s and 80’s. It’s only recently with DHTML and Ajax that browser UIs have caught up.

Today, though, the original reason for abandoning thick clients has gone away. On Windows, software is easily pushed to desktops using group policy or system management software. For a “pull” approach, .NET has ClickOnce and Java has Java WebStart. Even if these mechanisms didn’t exist, having the client software poll a server for updates is very simple. So simple that it doesn’t make sense for concerns about client software deployment overshadowing concerns about development productivity, usability, and total cost of ownership.

It’s time to bring back the thick client.

WPF Doodle #2: a tabbed rectangle

April 19th, 2008

Joshua Marinacci’s second JavaFX doodle is an animated tabbed rectangle. When pressing on a rectangle, a rectangle appears and expands. Once the rectangle reaches its full height, an animated tab grows out of the rectangle. As with the first JavaFx Doodle, Andres Almiray implemented the second JavaFx Doodle in Groovy.

Here’s my implementation of Doodle #2 in WPF:




The complete project is available here.

For this doodle, I created a custom control for the tab rectangle. Creating this control actually took me a couple of attempts. First I created the control in Expression Blend 2.5 by combining a rectangle and a couple of paths for the tab. This control worked but it didn’t leave me with something I could animate - the path segments were already precomputed. My next try focused on the animation aspects of the tab. I added “Arc” and “TabSize” dependency properties to provide some parameters that could be animated. I tried to produce the tabbed rectangle geometry within XAML, but either because of limitations in XAML or more likely in my skills, I had to resort to generating the geometry in C#. For the geometry, I added a third dependency property, “TabGeometry”. The tab geometry is automatically updated when any of the “Arc”, “TabSize”, “Height”, or “Width” properties are changed.

Here is the XAML for the tabbed rectangle:

<UserControl x:Class="Doodle2.TabRect" x:Name="UserControl">
  <Canvas>
    <Path Stroke="Black" StrokeThickness="3" Data="{Binding TabGeometry, ElementName=UserControl}">
      <Path.Fill>
        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
          <GradientStop Color="White" Offset="0"/>
          <GradientStop Color="Blue" Offset="1"/>
        </LinearGradientBrush>
      </Path.Fill>
    </Path>
  </Canvas>
</UserControl>

Most of the code-behind is boilerplate; see the full project for the details. The only portion that is interesting is the creation of the tabbed rectangle geometry which is done in the ComputeGeometry method:

private void ComputeGeometry()
{
  RectangleGeometry rect = new RectangleGeometry(new Rect(0, 0, Width, Height), Arc, Arc);

  PathSegmentCollection tabSegments = new PathSegmentCollection();
  tabSegments.Add(new LineSegment(new Point(Width / 2, Height + TabSize * 1.5), true));
  tabSegments.Add(new LineSegment(new Point(Width / 2 + TabSize, Height), true));
  PathFigure tabFigure = new PathFigure(new Point(Width / 2 - TabSize, Height), tabSegments, false);
  PathFigureCollection tabFigures = new PathFigureCollection();
  tabFigures.Add(tabFigure);
  PathGeometry tab = new PathGeometry(tabFigures);

  TabGeometry = new CombinedGeometry(tab, rect);
}


As you can see, WPF provides enough classes and methods to make creating this geometry trivial. Thanks to Charles Petzold’s Applications = Code + Markup book for usage examples.

Now that the tabbed rectangle is finished, it needs to be hosted and animated. I use the following XAML within a Window to display the tabbed rectangle and star. Thanks to Mark Heath for the XAML star.

<Canvas x:Name="LayoutRoot">
  <Doodle2:TabRect Opacity="0" Width="100" Height="50" x:Name="tabRect" Canvas.Left="20" Canvas.Top="20"/>
  <Path x:Name="path" Stroke="#000080" Fill="#FFFF00" StrokeThickness="3" StrokeStartLineCap="Round"
    StrokeEndLineCap="Round" StrokeLineJoin="Round" Canvas.Top="69" Canvas.Left="163"
    Data="M 0,0 l 10,0 l 5,-10 l 5,10 l 10,0 l -7,10 l 2,10 l -10,-5 l -10,5 l 2,-10 Z"/>
</Canvas>


The animation storyboard is very simple. The only interesting point is that the begin time for animating the TabSize is delayed:

<Storyboard x:Key="TabAnimate">
  <DoubleAnimation Storyboard.TargetName="tabRect" Storyboard.TargetProperty="(FrameworkElement.Height)"
   From="0" To="100" Duration="0:0:01" BeginTime="0:0:00"/>
  <DoubleAnimation Storyboard.TargetName="tabRect" Storyboard.TargetProperty="(FrameworkElement.Opacity)"
   From="0" To="100" Duration="0:0:01" BeginTime="0:0:00"/>
  <Int32Animation Storyboard.TargetName="tabRect" Storyboard.TargetProperty="(Doodle2:TabRect.Arc)"
   From="0" To="10" Duration="0:0:01" BeginTime="0:0:00"/>
  <Int32Animation Storyboard.TargetName="tabRect" Storyboard.TargetProperty="(Doodle2:TabRect.TabSize)"
   From="0" To="0" Duration="0:0:01" BeginTime="0:0:00"/>
  <Int32Animation Storyboard.TargetName="tabRect" Storyboard.TargetProperty="(Doodle2:TabRect.TabSize)"
   From="0" To="10" Duration="0:0:00.3" BeginTime="0:0:01"/>
</Storyboard>


Finally, the animation is triggered via a MouseDown event:

<EventTrigger RoutedEvent="Mouse.MouseDown" SourceName="path">
  <BeginStoryboard Storyboard="{StaticResource TabAnimate}"/>
</EventTrigger>


As with the first doodle, I think the WPF implementation stacks up well against the JavaFX and Groovy GraphicsBuilder implementations.

PDX Webfoot

April 16th, 2008

I attended the PDX Webfoot conference this last Saturday. Unfortunately the day was unseasonably warm - probably the best weather Portland has seen in 5 months. Conference attendance was severely affected with only about 15 people showing up. The conference organizers quickly streamlined the schedule to get us out early to enjoy some of the sun.

Most of the sessions were introductions Silverlight. I started learning Silverlight 2 a couple of weeks ago and programmed in WPF a bit, so the introductory sessions did not present any new material to me. Us early adopters will have to suffer through more Silverlight introductions over the next few months until more advanced usages are common.

One particularly interesting session was by Eric Mork of Silver Bay Labs. Eric and his wife have quit their day jobs and are focusing on Silverlight consulting. They hope to get in on the ground floor of this new technology. That’s interesting to me because I am thinking along the same lines. If Silverlight takes off there will be need to be training, advanced documentation, custom controls, and various other consulting opportunities.

It was a shame to spend a glorious weekend afternoon indoors, but I am satisfied with the contacts I made at the conference. Sunday was not as nice but I did get in a good 38 mile bicycle ride.

WPF Doodle #1

March 18th, 2008

Joshua Marinacci started it with his JavaFX Doodle #1. Andres Almiray continued it with a Groovy GraphicsBuilder groodle. These days, I’m more interested in WPF and Silverlight than anything else, so I decided to implement these doodles in WPF and/or Silverlight.

Here’s doodle #1 in WPF:

A screenshot of my WPF Doodle #1

The base page and window are very simple (I’ve stripped out the namespace declarations):

<Window x:Class="Doodle1.Window1" x:Name="Window" Title="WPF Doodle #1" Width="400" Height="400">
  <UniformGrid x:Name="LayoutRoot" Columns="20" Rows="20" Background="Black"/>
</Window>


The UniformGrid is a lot like a JPanel with a GridLayout layout manager and relieves me of having to do any layout or sizing of the cells.

Code behind is required because XAML, being a declarative language, doesn’t have any looping constructs:

public partial class Window1 : Window
{
  public Window1()
  {
    this.InitializeComponent();
    for (int x = 0; x < LayoutRoot.Columns; x++)
    {
      for (int y = 0; y < LayoutRoot.Rows; y++)
        LayoutRoot.Children.Add(new Cell());
    }
  }
}


The final part of the doodle is the definition of a Cell. A Cell is defined purely in XAML:

<UserControl x:Class="Doodle1.Cell" x:Name="UserControl">
  <Rectangle x:Name="LayoutRoot" Fill="Black">
    <Rectangle.Triggers>
      <EventTrigger RoutedEvent="Rectangle.MouseEnter">
        <EventTrigger.Actions>
          <BeginStoryboard>
            <Storyboard TargetProperty="Fill.Color">
              <ColorAnimation From="Black" To="Yellow" Duration="0:0:3" AutoReverse="True"/>
            </Storyboard>
          </BeginStoryboard>
        </EventTrigger.Actions>
      </EventTrigger>
    </Rectangle.Triggers>
  </Rectangle>
</UserControl>


There’s more XAML verboseness here than anything else, but this control should be easy to understand. When the mouse enters the cell, it triggers the color animation which changes the fill color from black to yellow and back again.

I think this implementation of Doodle #1 stacks up well with the JavaFX and Groovy implementations. I’m sure some one more knowledgeable and experienced in XAML can simplify the XAML further.

Source Code for .NET!

October 3rd, 2007

Wow, Microsoft is finally making the source code for .NET available! It was crazy that it wasn't available from the get go considering that their biggest competitor, Java, was already doing this.

I learned a lot about the Java class libraries by going through the Java source code. Now it'll be even easier to come up to speed on .NET. Plus, it'll make debugging .NET code even easier.

Now that it's dark in the evenings (and wet the rest of the time), I'm burning to get started learning WPF and Silverlight. I absolutely must get a new laptop though. The Dell Vostro with the 17″ screen looks nice except that the fastest available hard drive is 5400 rpm. It also comes with Vista which, from what I've read, is a disappointment. I own XP SP2 for my current laptop. I'd retire that laptop, but I bet the OEM license prevents me from legally installing it's OS onto another computer. Eh, I'll probably wait another week and buy the Vostro.