Griffon: Swing just got fun again
-
Upload
james-williams -
Category
Technology
-
view
3.430 -
download
0
description
Transcript of Griffon: Swing just got fun again
![Page 1: Griffon: Swing just got fun again](https://reader034.fdocuments.in/reader034/viewer/2022051411/5461f600b1af9f86228b4d30/html5/thumbnails/1.jpg)
Griffon
Swing just got fun againJames Williams
![Page 2: Griffon: Swing just got fun again](https://reader034.fdocuments.in/reader034/viewer/2022051411/5461f600b1af9f86228b4d30/html5/thumbnails/2.jpg)
Agenda
> What's un-fun about Swing?
> What is Griffon?
> Getting Started
> Builders
> Griffon MVC
> Lifecycle
> Plugins/Addons
> Demos
> Q&A
![Page 3: Griffon: Swing just got fun again](https://reader034.fdocuments.in/reader034/viewer/2022051411/5461f600b1af9f86228b4d30/html5/thumbnails/3.jpg)
What's un-fun about Swing?
> not knowing where stuff is
> can be very repetitive
> unresponsive user interfaces
> configuring webstart apps is a nightmare
> you're forced to choose between applets and desktop
fairly early
![Page 4: Griffon: Swing just got fun again](https://reader034.fdocuments.in/reader034/viewer/2022051411/5461f600b1af9f86228b4d30/html5/thumbnails/4.jpg)
What is Griffon?
> desktop framework leveraging Swing and Groovy
> Apache 2 Licensed
> very extensible with plugins and addons
> allows you to code without worrying about the destination
platform
![Page 5: Griffon: Swing just got fun again](https://reader034.fdocuments.in/reader034/viewer/2022051411/5461f600b1af9f86228b4d30/html5/thumbnails/5.jpg)
Griffon Application Structure
![Page 6: Griffon: Swing just got fun again](https://reader034.fdocuments.in/reader034/viewer/2022051411/5461f600b1af9f86228b4d30/html5/thumbnails/6.jpg)
Getting Started
> griffon create-app
> griffon run-app
> griffon run-applet
> griffon run-webstart
> griffon package
> griffon list-plugins
> griffon install-plugin
![Page 7: Griffon: Swing just got fun again](https://reader034.fdocuments.in/reader034/viewer/2022051411/5461f600b1af9f86228b4d30/html5/thumbnails/7.jpg)
Builders
> DSLs to compose complex object graphs
> Can automatically perform some common conversions
> Yield much more readable code than Java
![Page 8: Griffon: Swing just got fun again](https://reader034.fdocuments.in/reader034/viewer/2022051411/5461f600b1af9f86228b4d30/html5/thumbnails/8.jpg)
Would you prefer this ...
public class JavaFrame extends JFrame { public JavaFrame() { setLayout(new GridLayout(3,1)); setTitle("Test"); setSize(100,100); add(new JLabel("One")); add(new JLabel("Two")); add(new JLabel("Three")); }
public static void main(String [ ] args) { new JavaFrame().setVisible(true); }}
![Page 9: Griffon: Swing just got fun again](https://reader034.fdocuments.in/reader034/viewer/2022051411/5461f600b1af9f86228b4d30/html5/thumbnails/9.jpg)
... or this?
def swing = new SwingBuilder()
swing.frame(size:[100,100], title:'Test', layout:new GridLayout(3,1)){ label("One") label("Two") label("Three")}.show()
![Page 10: Griffon: Swing just got fun again](https://reader034.fdocuments.in/reader034/viewer/2022051411/5461f600b1af9f86228b4d30/html5/thumbnails/10.jpg)
30 sec Swing(X)Builder Quick Guide
> Take the class name (e.g. JFrame)
> Remove the J(X)
> Change the remaining node name to camel-case
> Any fields that follow the JavaBean spec can be passed in
a HashMap
![Page 11: Griffon: Swing just got fun again](https://reader034.fdocuments.in/reader034/viewer/2022051411/5461f600b1af9f86228b4d30/html5/thumbnails/11.jpg)
UberBuilder - Builders on steriods
> Allows you to mix and match components
> Avoids collisions by setting up namespaces
![Page 12: Griffon: Swing just got fun again](https://reader034.fdocuments.in/reader034/viewer/2022051411/5461f600b1af9f86228b4d30/html5/thumbnails/12.jpg)
UberBuilder - Supported toolkits
> Swing
> SwingX
> JIDE
> Flamingo
> MacWidgets
> SwingXtras
> Fx (JavaFX)
> Gfx (Java2D)
![Page 13: Griffon: Swing just got fun again](https://reader034.fdocuments.in/reader034/viewer/2022051411/5461f600b1af9f86228b4d30/html5/thumbnails/13.jpg)
Griffon MVC Groups
> Models - can use the @Bindable notation to provide data binding
- store the data for the MVC Group
> Views - represent a single display in your applications
- can be written in Groovy OR Java
> Controllers - the brains of the group
- can be injected with services
![Page 14: Griffon: Swing just got fun again](https://reader034.fdocuments.in/reader034/viewer/2022051411/5461f600b1af9f86228b4d30/html5/thumbnails/14.jpg)
Binding
> general formats: - bind{model.property}
- bind(target:model, targetProperty:'name')
- bind(source:model, sourceProperty:'name')
> one-way
> mutual binding
![Page 15: Griffon: Swing just got fun again](https://reader034.fdocuments.in/reader034/viewer/2022051411/5461f600b1af9f86228b4d30/html5/thumbnails/15.jpg)
Binding and SwingPad Demo
![Page 16: Griffon: Swing just got fun again](https://reader034.fdocuments.in/reader034/viewer/2022051411/5461f600b1af9f86228b4d30/html5/thumbnails/16.jpg)
Griffon Lifecycle
> Initialize - run before any Swing code is started
> Startup - run after MVC Groups are initialized
> Ready - run after all events have been processed by the EDT
> Shutdown - all cleanup operations should run here
> Stop - only used by applets
![Page 17: Griffon: Swing just got fun again](https://reader034.fdocuments.in/reader034/viewer/2022051411/5461f600b1af9f86228b4d30/html5/thumbnails/17.jpg)
The Evil Event Dispatching Thread
> edt - runs on the EDT using invokeAndWait
> doLater - runs on the EDT using invokeLater
> doOutside - spins up a thread to run if not already outside the EDT
> withWorker (SwingWorker) - for long running tasks where the UI might periodically update
![Page 18: Griffon: Swing just got fun again](https://reader034.fdocuments.in/reader034/viewer/2022051411/5461f600b1af9f86228b4d30/html5/thumbnails/18.jpg)
Plugins
> are the delivery method to provide compile-time
functionality: - Builders
- Other JVM Language Support
- Testing Frameworks
- Addons
![Page 19: Griffon: Swing just got fun again](https://reader034.fdocuments.in/reader034/viewer/2022051411/5461f600b1af9f86228b4d30/html5/thumbnails/19.jpg)
Addons
> add functionality at run-time
> can add or respond to runtime events
> can decorate MVC Groups
![Page 20: Griffon: Swing just got fun again](https://reader034.fdocuments.in/reader034/viewer/2022051411/5461f600b1af9f86228b4d30/html5/thumbnails/20.jpg)
Guice Add-on
> injects methods and fields using the @Inject annotation
> Groovy removes the need for binding interfaces to
modules
> smaller footprint and faster than Spring
![Page 21: Griffon: Swing just got fun again](https://reader034.fdocuments.in/reader034/viewer/2022051411/5461f600b1af9f86228b4d30/html5/thumbnails/21.jpg)
Guice Configurationapplication { title='TestGuice' startupGroups = ['TestGuice']
// Should Griffon exit when no Griffon created frames are showing? autoShutdown = true
// If you want some non-standard application class, apply it here //frameClass = 'javax.swing.JFrame'}/* truncated for brevity */
guice { injectInto = ["controller"] modules = ['NotifierModule']}
![Page 22: Griffon: Swing just got fun again](https://reader034.fdocuments.in/reader034/viewer/2022051411/5461f600b1af9f86228b4d30/html5/thumbnails/22.jpg)
GuiceControllerclass TestguiceController { // these will be injected by Griffon def model def view @Inject Notifier notifier
void mvcGroupInit(Map args) { // this method is called after model and view are injected injector.injectMembers(this) // related settings from Application.groovy are injected notifier.sendNotification("hi") }}
![Page 23: Griffon: Swing just got fun again](https://reader034.fdocuments.in/reader034/viewer/2022051411/5461f600b1af9f86228b4d30/html5/thumbnails/23.jpg)
Griffon Links
> Download: http://griffon.codehaus.org/Download
> Plugins/Addons: http://griffon.codehaus.org/Plugins
> User mailing list: [email protected]
> Dev mailing list: [email protected]
![Page 24: Griffon: Swing just got fun again](https://reader034.fdocuments.in/reader034/viewer/2022051411/5461f600b1af9f86228b4d30/html5/thumbnails/24.jpg)
Griffon Team on Twitter
> James Williams (@ecspike)
> Danno Ferrin (@shemnon)
> Andres Almiray (@aalmiray)
> Josh Reed (@joshareed)
> Jim Shingler (@jshingler)
> Griffon News (@theaviary)