// Store the given properties for later use.
properties = props;
// Create the MapHandler, which allows all the components to
// find each other if they are added to it.
MapHandler mapHandler = new MapHandler();
// Create the MapBean.
MapBean map = new MapBean();
// Set the map's center property
map.setCenter(new LatLonPoint(43.0f, -95.0f));
// Add the MapBean to the MapHandler.
mapHandler.add(map);
// Add the map to the JFrame
getContentPane().add(map, BorderLayout.CENTER);
// Create a mouse delegator to handle mouse events on the map
mapHandler.add(new MouseDelegator());
// Create and add the MouseMode that the RouteLayer wants
// events from. The MouseDelegator asks all layers which
// MouseMode they listen to, and hooks them up. When that
// MouseMode is active, events flow to the top layer, then
// down to lower layers if the event is not consumed along the
// way.
mapHandler.add(new SelectMouseMode());
// Add a LayerHandler, which manages all layers, on or off.
mapHandler.add(new LayerHandler());
// Create and add a Political Background
Layer layer = createPoliticalLayer();
if (layer != null)
mapHandler.add(layer);
// Create and add a Route Layer. The LayerHandler will find
// it via the LayerHandler, and then the LayerHandler will add
// it to the map because layer.isVisible() == true;
layer = createRouteLayer();
if (layer != null) {
layer.setName("Routes");
mapHandler.add(layer);
}
// Add some navigation tools. The ToolPanel will find the
// OMToolSet (a Tool) in the MapHandler.
ToolPanel toolPanel = new ToolPanel();
mapHandler.add(toolPanel);
mapHandler.add(new OMToolSet());
// Add the ToolPanel to the JFrame.
getContentPane().add(toolPanel, BorderLayout.NORTH);
// Oh, for fun, lets add a GUI to control the layers. A
// button to launch it will get added to the ToolPanel.
mapHandler.add(new LayersPanel());
// You can add other components from the com.bbn.openmap.gui
// package...
}