Java Reference
In-Depth Information
This code is basically the same as what you saw back in chapter 4 for publishing ser-
vices. The only difference is that you use the system bundle's bundle context to regis-
ter the service, because the application doesn't have its own bundle context. Of
course, what makes this possible is the fact that you're using the same org.foo.shape
package on the inside and the outside, which means your trapezoid shape works just
like the shapes provided by any of the shape bundles.
Now you're ready to bind everything together to complete the functioning paint
program.
CREATING THE PAINT FRAME
The createPaintFrame() method performs nearly the same functionality as the bun-
dle activator for the original paint bundle from chapter 4. The details are shown in
the following listing.
Listing 13.8 Creating the paint frame and binding it to the framework instance
...
private static void createPaintFrame() throws Exception {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
frame = new PaintFrame();
frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent evt) {
try {
fwk.stop();
fwk.waitForStop(0);
} catch (Exception ex) {
System.err.println("Issue stopping framework: " + ex);
}
System.exit(0);
}
});
frame.setVisible(true);
shapeTracker = new ShapeTracker(fwk.getBundleContext(), frame);
shapeTracker.open();
}
});
}
You create the paint frame itself and then add a window listener to cleanly stop the
embedded framework instance and exit the JVM process when the frame is closed.
Then you display the paint frame; but at this point it isn't hooked into the embedded
framework instance. You get the system bundle's bundle context and use it to create a
shape tracker for the paint frame B ; this is what binds everything together. Due to the
original design, you don't need to spread OSG i API usage throughout the application.
To run the standalone paint program, go into the chapter13/paint-example/
directory. Type ant to build the program and java -jar paint.jar to run it. Fig-
ure 13.5 shows the result.
Creates and starts
shape tracker
B
Search WWH ::




Custom Search