Swing usage

The library comes with a Swing sample application and a set of classes that goes with. The application itself is SampleApp. To try it, you simply type the follwing command from the main directory:

    mvn compile exec:java

Or use this link to start it with WebStart (no download or installation required apart from a Java JRE).

You have first to load maps by selecting a file or a whole directory in the "Open" dialog (CTRL-O). Then, you drag the map to move it and use the scroll-wheel to zoom.

How it works

Here is the code to have a swing panel containing a map:

    MapPanel<Point2D.Double> mapPanel=
        new MapPanel(new NullConverter(), 0);

    File file=new File("/home/patrick/gps/maps/00000002.img");



The generic parameter of the MapPanel class defines the class used for coordinates. Then, the object passed to the constuctor defines how to use those coordinates to project the coordinates on the screen. In the previous example, we use the NullConverter and a pair of doubles as coordinates.

The MapPanel class uses one thread (MapPanelThread) to be able to draw the map while still allowing the user to move and zoom in the map.

A chain of listeners is used to draw the map:

The MapDrawer listener is using a LabelDeClutteringFilter for having some help in drawing labels.

Required libraries

Some external libraries are used in SampleApp:

  • Batik: export to SVG files
  • iText: export to PDF files

They are included in the JGarminImgParser package.


Thanks goes to: