|
9.1. Getting StartedIn this section, you'll start creating a rich client RentABike with an emerging project built directly on the Spring Framework, the Spring Rich Client Project (Spring Rich). The first thing you'll do is get the necessary project files. You'll then see how to get a basic application shell with a splash screen up and running. But first, a brief background on the aims of the project At its core, Spring Rich is a framework for constructing high-quality, professional Swing-powered desktop applications. It serves several important needs:
9.1.1. How do I do that?You first want to get the Spring Rich project. Link to it from the Spring site at http://www.springframework.org and follow the directions that you see there. In a nutshell, you will:
Note: Spring Rich ships two distributions for each release: a bare-bones distribution containing the minimal jars, and an all-in-one jar also containing all dependencies. The "with dependencies" release has everything that you need, including Spring Rich and all of its dependencies. The project is still rapidly evolving, so if you need to download and build the latest CVS snapshot to take advantage of the newest to-be released features, do the following:
Now you've got the spring-richclient.jar, which you can plug right into your project. You're also going to need a set of image resources. Spring Rich ships a set of out-of-the-box images in spring-richclient-resources.jar you can use to jumpstart your UI development. You can also take the images that we packaged with the book's code examples and use them where an example calls for images. Move the jars into your lib directory under your project, and you're off to the races. You'll next configure a splash screen and code a thin application bootstrapper to make sure that things are working. A startup application context, which hosts services needed at initialization, defines your splash screen (Example 9-1). Example 9-1. startup-context.xmlcom.springbook.richclient.startup-context.xml <beans> <bean > <property name="imageResourcePath"> <value>classpath:/images/splash-screen.jpg</value> </property> </bean> </beans> Of course, you'll want to get a designer to build you an outrageously cool splash screen, but we all failed art, so you're on your own. In the mean time, you can use a simple JSP like the one in Example 9-2. Example 9-2. splashScreen.jsp<HTML> <BODY> Keith's Bikes </BODY> </HTML> You'll then want a simple main driver to kick of loading your application (Example 9-3). Note: This is the main driver that starts the bikestore springbook application. Example 9-3. RentABikeLauncher.xmlpublic class RentABikeLauncher { public static void main(String[] args) { try { String packagePrefix = "com/springbook/richclient"; String startupContextPath = packagePrefix + "/startup-context.xml"; String[] rootContextPath = new String[] { packagePrefix + "/business-layer-definitions.xml", packagePrefix + "/richclient-definitions.xml" }; new ApplicationLauncher(startupContextPath, rootContextPath); } catch (Exception e) { System.exit(1); } } } This thin bootstrapper uses ApplicationLauncher to load your application from the configuration defined in two spring application contexts. In a standalone rich client environment, you'll typically specify three context configuration files on the classpath. The first configuration file is startup-context.xml, which you just defined with your splash screen bean definition. The next two files are business-layer-definitions.xml and richclient-definitions.xml. These make up the central root application context, which you will define and configure in the next lab. You're ready to let it fly. 9.1.2. What just happened?Like most rich client apps, Spring Rich-powered apps can take a little bit of time to launch, so the framework lets you put up a splash screen when you launch your application while the user waits. As you've seen, Spring Rich lets you specify the splash-screen configuration in the context. There's more to it than meets the eye. The framework forks off a thread for you, and loads your application while you look at the pretty splash screen. That way, the user gets the impression of immediate response. This boilerplate code exists in most rich client applications, but is completely managed by the framework. |
|