James Williams
LinkedInMastodonGithub

Porting a Groovy app to Griffon

Just before launch, I started porting the Groovy port of jFlubber to Griffon. I would have included some screenshots but it looks the same. I'll be delving into the code a bit so take and minute to download the old and new versions. On the changes:

Resources

The original app lived in one mess of a directory along with the images. Images now live in the resources directory and are properly separated from the code.

Helper classes

Also in the main src directory were two helper classes to encapsulate some Java Timer capabilities(GroovyTimerTask and UpdateTimeTask). Though Griffon will be able to locate them in the view directory, they are not in and of themselves views. It's more appropriate for them to be outside the Griffon MVC architecture in src/main/groovy.

MVC

By far, this was the area that benefited the most from the port. What began as a big clusterf--k all in one file has evolved to a nice separation of MVC. Thanks to @Bindable and changing from a concrete class as a view to a view clousure, I was able to eliminate some useless instance variable move what needed to referenced from the view to the model.

import groovy.beans.Bindable 
import org.jdesktop.swingx.* 
import org.jdesktop.swingx.painter.* 

class GriffonFlubberModel { 
    @Bindable String timeText = '0:00'
    @Bindable String flubText = ''
    @Bindable TextPainter timeLabel 
    @Bindable Timer timer 
    @Bindable long startTime = 0L 
    @Bindable int labelNo = 0 
}

Likewise most of the helper functions for the view moved to the controller.