Global Positioning System Reference
In-Depth Information
Note that this method can only be overridden inside the inherited class
due to the protected visibility. Again the method is invoked by the frame-
work, when it is the component's turn to paint itself. The Graphics class
provides methods for the remaining requirements to draw a (map) image
and geometric figures:
drawText() drawString()
drawPolyLine() drawLine()
drawPolygon() fillPolygon()
drawRect()
fillRect()
The implementation of these methods can be found in the API of the
MapPanel (see UML diagram in Figure 5.1). The prefix paint... is used
in the component's context to refer to paintComponent with a Graphics
instance as the argument, while the prefix draw... refers to the Graphics
drawing methods.
Now, the MapPanel can be used to display geometries on a map with GPS
positions. Note that all drawing elements are passed to the map panel with
fixed-size arrays, the simplest and fastest collections. This design enforces
an external management of the arrays. To add or remove elements, a new
array has to be passed again to draw methods to refresh the map display.
5.6
Creating a Swing Mapping Application
The advantage of creating a Swing MapPanel is that every programmer
familiar with Swing can create his personal Swing application and add a
map in the same way as adding any other component. For example, the
map can be placed in the Swing containers JScrollPane and JSplitPane .
Of course, Swing has its own specifications; for example, a beginner
might be confused when trying to position his components explicitly. Gen-
erally speaking, layout managers (over)rule size and location of Swing com-
ponents placed inside containers. Although Swing allows you to turn them
of it is not a good idea, since you loose a lot of functionality required for
windowing systems. This is especially undesirable when the GUI needs to
fit the screen size of hand-held devices.
When displaying a map (image), resizing of the map can be irritat-
ing to the user. It also consumes CPU power by rescaling every map
item. We therefore add another Swing component to the map package: the
MapScrollPane . It extends the JScrollPane .
TheJavaTutorial>CreatingaGUIwithJFC/Swing>ScrollPanes
A JScrollPane provides a scrollable view of a component.
When screen real estate is limited, use a scroll pane to dis-
 
Search WWH ::




Custom Search