Spring Rich Client - Part 1
Spring Rich Client - Part 1
Join the DZone community and get the full member experience.Join For Free
Get the Edge with a Professional Java IDE. 30-day free trial.
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.