Spring Rich Client - Part 1
Join the DZone community and get the full member experience.Join For Free
today i will start a series about the great swing framework called spring rich client (src). the 1.0.0 version was released in march 2008 and it is not inactive as i thought before.
you can get more information about src from:
why i listed the forum as the first point? because for a beginner like me it was the best source of information (after the samples).
so, let us set up a hello world example.
if you use my hello world skeleton you should open it in netbeans, right click on the project node and resolve reference problems. then go to the place where you have unzipped the src and add the first jar file. the other jar files should be added automagically for you.
the project with dependencies would be about 2.7 mb, it is not a small overhead, but okay, i think. as an example for the reader one can compare it to the minimal size of the netbeans or eclipse rcp.
now it is time to start the project with f6 or run->’run main project’. you should see the frog-splashscreen and the final view:
now let me explain several things that one could customize in src. please see the resources section for the result of customization.
as the first point i wanted to know how easy it is to introduce docking capabilities (vl docking). it was really easy!
- add spring-richclient-docking.jar and vldocking.jar
- and change 2 things in the richclient-application-context.xml file:
- change class of initialview to org.springframework.richclient.application.docking.vldocking.vldockingviewdescriptor
- add a applicationpagefactory to the richclient-application-context.xml
then you can add a new window to see the results of dragging:
- create the class view2
add the following to the richclient-application-context.xml:
<bean id=”view2″ class=”org.springframework.richclient.application.docking.vldocking.vldockingviewdescriptor”> <property name=”viewclass” value=”de.peterk.springr.view2″ /> <property name=”autohideenabled” value=”true” /> <property name=”closeenabled” value=”true”/> </bean>
and you are done! just start the application go to windows->show view->view2
now, how easy is it to use your own layout? configuring the look and feel:
remove the lookandfeelconfigurer and add instead:
<bean id=”lookandfeelconfigurer” class=”de.peterk.springr.ui.kunststoffconfigurer”></bean>
- remove looks.jar: 350 kb
- add kunststoff : 17 kb
- add the kunststoffconfigurer class to the source package
okay, then changing the splash screen is trivial: just overwrite the splash-screen.png or change the path in the richclient-startup-context.xml file.
now we should adjust the size of the view, this can be done with 2 lines in the method simplelifecycleadvisor.onprewindowopen:
rectangle rect = graphicsenvironment.getlocalgraphicsenvironment().getmaximumwindowbounds(); configurer.setinitialsize(new dimension(rect.width, rect.height));
and to translate the messages simply copy all property files to e.g. file_de.properties and translate them! in our case it means “cp message.properties message_de.properties”. if you want to add a translateable tool tip of the initalview-label just use:
- in initialview.createcontrol and add the property initialview.tooltip to the property file.
to set a keyboard shortcuts e.g. to leave the application. you need to add one line to the message.properties file
- exitcommand.label=exit@ctrl q
another interesting action (in src they will be called commands) could be restart. so how can we add the action into the menu? you have to add
- restartcommand.label=restart@ctrl r
- in the message.properties file and use
- application.instance().start(); application.instance().getactivewindow().close();
- within your restartcommand class. then add
- <bean class=”de.peterk.springr.restartcommand” />
- into the commands-context.xml (e.g. after <value>propertiescommand</value> in filemenu)
the final result is:
here you can download the extended “hello more” sample (a netbeans 6.1 project about 90 kb, without dep). the full project was 2.9 mb.
one can say that spring rich client is a powerful jar collection :-). but i would say src is a great way for your next swing application!
it is very intuitive to use: the whole sample (including to write this blog) took me only about 6 hours. i think you could be really productive with it! in the case i published the documents with mistakes: please leave your comment here!
Opinions expressed by DZone contributors are their own.