advertisement
javaboutique
Search Tips
Articles  |   Tutorials  |   Reviews  |   Tools  |   by Category  |   by Date  |   by Name  |   Submit  |   Source  |   Forums  |  
javaboutique
Browse DevX


Partners & Affiliates











advertisement

Tutorials : Deliver On-the-Fly Mapping Services to Your Rich Desktop Java Application, Part 3 :

The Rich Client Mapping Application

This article's rich Java mapping application consists of only three classes, all of which are located in the ca.ansir.app package. MappingApplication is the main class and extends JFrame. The following code shows how the Map is created and added to the layout of the main class.
public MappingApplication() {
  super("Mapping Application Client");
  URL url = XMLTileFactoryParser.class.getResource("helloworld.xml");
  StringBuffer message = new StringBuffer();
  xmlTileFactory = XMLTileFactoryParser.getXMLTileFactory(url
      .toExternalForm(), message);
  if (xmlTileFactory == null) {
    throw new RuntimeException(
        "Programming error: Could not find helloworld.xml");
  }
  map = new Map(xmlTileFactory, 0);
  map.setPreferredSize(new Dimension(550, 400));
  JPanel contentArea = new JPanel(new BorderLayout());
  contentArea.setBorder(PanelUtility.GAP_1X_PANEL_BORDER);
  contentArea.add(map, BorderLayout.CENTER);
  getContentPane().add(contentArea, BorderLayout.CENTER);
  setUpMenu();
  setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
For an initial XMLTileFactory, you'll use the helloworld.xml configuration from Part 2. Your parser class, XMLTileFactoryParser, creates an XMLTileFactory for you. The XMLTileFactory object will always contain a list of one or more XMLTileFactoryInfo objects and the index of zero will always safely index the first XMLTileFactoryInfo object in the list. Your Map object is constructed using the XMLTileFactory and the index of zero to specify the first XMLTileFactoryInfo object.

Before the constructor ends, it invokes the setUpMenus method (Listing 1). The setUpMenus does three things:

  1. It creates the application's menu bar, and then adds a file menu with an exit action to it.
  2. It creates a viewMenu member which is added to the menu bar. The view menu is then configured and reconfigured each time a new XmlTileFactory is used, so a separate method is used to set up the view menu's items.
  3. It adds a tools menu to the menu bar.

In the setUpViewMenu method, create a radio button menu item for each of the one or more XMLTileFactoryInfo objects in your list. Each of these radio button menu items uses an instance of ViewItemListener which encapsulates the corresponding index in your list. You'll use the TileFactoryInfo metadata (discussed in Part 2) for the name and tooltip of these radios. Selecting one of these radios invokes the map's setTileFactory method along with the appropriate index. Finally, add a separator to the view menu and a check box menu item to show and hide your map's mini map.

So, you know why you created a separate setUpViewMenu method and what that menu does, but you don't know how to invoke the method multiple times. This is where things get interesting. Earlier, you saw that one advantage of using an XML configuration for tile URL generation is the ability to update or plug-in new configurations without recompiling the Java code.

The tool menu provides the mechanism to demonstrate how a new XML configuration can be selected on the fly. Your TileFactoryDialogAction shows the TileFactoryDialog (Figure 1), which is the second class in the ca.ansir.app package. When the TileFactoryDialog is closed (and if a new XMLTileFactory has been selected in the dialog), then you invoke the setUpViewMenu dialog again and the new configuration becomes available to the application.


Figure 1. TileFactoryDialog: Here shown with MappingApplication in the background.

The TileFactoryDialog has a help button, which takes youto a list of test XML configurations. The TileFactoryDialog's preview button shows a preview of the selected XML configuration. The TileFactoryPreviewDialog (Figure 2) is the third and final class in the class in the ca.ansir.app package.


Figure 2. The TileFactoryPreviewDialog: This shows a preview of the selected XML configuration.

The code for the final part of this series is available as an Eclipse project here. Depending on your Eclipse environment, you may need to change the build path to use a specific jdk1.5+ installed on your system. Alternately, there is an Ant build.xml file to build and run the project.

Your rich Java mapping client was motivated by the need identified in Part 1. Leveraging the SwingX-WS project's JXMapKit with the XML configuration and code developed in Part 2, your mapping client demonstrates that new mapping configurations can be plugged into a rich Java client on the fly without the need to recompile Java code.

About the Author
Dan Andrews is the President of Ansir Development Limited. He has been a Sun Certified Programmer for the Java(tm) 2 Platform since 1999. Prior to founding Ansir Development Limited in 2005, Dan worked at SED Systems as a programmer analyst. At SED, he worked on building large Swing applications which help control some of the world's largest satellite networks and deep space antennas.

Home / Articles / Deliver On-the-Fly Mapping Services to Your Rich Desktop Java Application, Part 3 / 1 / 2 / 3 /

How to Add Java Applets to Your Site

New on the Java Boutique:

New Review:

Time Management Made Easy with the Quartz Enterprise Job Scheduler
Why not just use the Java timer API? This open source scheduling API boasts simplicity, ease-of-integration, a well-rounded feature set, and it's free!

New Applet:

Reverse Complement
Reverse Complement is a simple applet that converts DNA or RNA sequences into three useful formats.

Elsewhere on internet.com:

WebDeveloper Java
Lots of Java information on webdeveloper.com

WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.

ScriptSearch Java
Hundreds of free Java code files to download.

jGuru: Your View of the Java Universe
Customizable portal with online training, FAQs, regular news updates, and tutorials.

 Internet.com eBook Library
 IBM Software Construction Toolbox
 Microsoft RIA Development Center
 Destination .NET
XML error: not well-formed (invalid token) at line 38
advertisement
Receive Articles via our XML/RSS feed
Receive Articles via our XML/RSS feed

JavaBytes
Internet Cyclone
This powerful, easy-to-use, internet optimizer is for Windows 95, 98, ME, NT, 2000 and XP. It's designed to automatically optimize your Windows settings, boosting your Internet connection up to 200%.

Mozilla's Ubquity Mashup: For The Masses?
iPhone Users Just Want to Have Fun
Oops! I Fixed the Linux Kernel
Jim Zemlin: The New Center of Linux Gravity
Microsoft's Novell Investment Tops $340M
Fedora 10 Takes Shape
IBM Gives a Mobile Voice to Developers
Inadequate Tools Send Software Down the Drain
USB 3.0 One Step Closer to Reality
Would-Be Linux Contributors May Get a Leg Up

Develop a Mobile RSS Feed the Easy Way
State of the Semantic Web: Know Where to Look
A 3D Exploration of the HTML Canvas Element
Setting Up and Running Subversion and Tortoise SVN with Visual Studio and .NET
Java/JRuby Developers, Say Open 'Sesame' to the Semantic Web
Interpreting Images with MRDS Services
DevXtra Editors' Blog: Executives Avoiding Cloud Computing in Droves
Q&A with James Reinders on the Intel Parallel Studio Beta Program
The Pros and Cons of Outsourcing Enterprise Emails
Hosting Options: Shared or Dedicated Server

Advertising Info  |   Member Services  |   Contact Us  |   Help  |   Feedback  |   Site Map  |   Network Map  |   About



JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers