In this topic
- Creating a project
- Creating an ArcGIS Engine library
- Building an ArcGIS Engine application
- Completing the code and initializing the ArcGIS Engine license
Creating a project
- Click File, New, and Java Project. See the following screen shot:
- Type ArcGIS_Engine in the Project name field. Leave the other options set with the default values. Click Finish. See the following screen shot:
- When you click Finish in the preceding screen shot, the ArcGIS_Engine project appears in the Package Explorer. See the following screen shot:
Creating an ArcGIS Engine library
Before building the application, set up the libraries the application will use. Create a new library containing the ArcGIS Engine Java Archive (JAR) files needed to get started.
- In the Package Explorer, right-click ArcGIS_Engine and click Properties. See the following screen shot:
- In the left-hand panel, click Java Build Path. In the right-hand panel, click the Libraries tab and click Add Library. See the following screen shot:
- Click ArcObjects Library and click Next. See the following screen shot:
- After you click Next in the preceding screen shot, Select the ArcGIS Engine radio button. Click Finish to create the library. See the following screen shot:
- After you click Finish in the preceding screen shot, Arcobjects Library appears in the list of libraries. Click OK to add it to the project. See the following screen shot:
Building an ArcGIS Engine application
Before continuing on in this topic, now is a good time to update your Eclipse with a visual editor. Eclipse itself does not include a visual editor of its own, but there are a number of Eclipse plugin providers that enable you to visually build Java GUI applications such as the one we will build here. For the sake of this topic, we've chosen WindowBuilder. It is freely available for download at http://www.eclipse.org/windowbuilder/ . Make sure you have fully installed this plugin into your Eclipse IDE before moving to the next steps.
- Create a visual class that will be the basis for the application. Right-click the ArcGIS_Engine project. Choose New, and 'Other…'. See the following screen shot:
- Browse to the WindowBuilder folder, expand it, and expand the 'Swing Designer' folder. Choose 'JFrame' and hit Next:
3. Set the properties of the new visual class. Change the name to EngineApp.
4. Click Finish. See the following screen shot:
You will use the default package for this simple application, but larger applications should create new packages.
The Eclipse interface will now appear similar to the following screen shot:
Just below the code editing view, click the 'Design' tab. This will switch your view from code editing to visual design:
Now, your editor should look like the following:
- Create a new Palette category for the ArcObjects visual beans, so they appear available in the Palette window. In the Palette window, right click and select 'Add category. Give it the name 'ArcObjects'. A new empty folder/category will appear :
- Right click on the ArcObjects category folder and choose 'Import jar…'. Browse to where the arcobjects.jar file is on your file system:
You will see a list of all the visual beans available in the arcobjects.jar. Check them all and click 'OK' to finish the import.
- Now, your ArcObjects category should contain the visual beans used to visually build your Engine application:
Click TOCBean and click the West frame. The content pane automatically places the frame to the left side:
- Type TOC in the Name dialog box and click OK. See the following screen shot:
- Click MapBean from the palette and click the center portion of the frame.
- Click ToolbarBean from the palette and click the North section. Name the North section ToolBar. See the following screen shot:
- Building the simple application for the framework is complete. Now, the visual bean properties must be set to properly interact with each other. Click the ESRI TOCControl to make it active. In the Property list, click the 'Show advanced properties, and find the BuddyControl property. Click the '…' button in the Value column to show a list of the applicable values. The Map value entered in Step 11 for the MapBean in the application appears. Click Map to set the property. See the following screen shot:
- The ToolBarBean needs the same property set. Activate the ESRI ToolBarControl and also set its BuddyControl property to Map. All the components are ready to interact with each other. The next step is to add data to the map and tools to the toolbar.
- Right-click the ESRI MapControl and click Customize. See the following screen shot:
Various properties for the map can be set, but at this point choose a map document to display. Click the open folder button and browse to a *.mxd file (ArcGIS/java/samples/data/mxds/usa.mxd). Click OK to close the dialog box. See the following screen shot:
- Right-click the ESRI ToolBarControl and open its Customize dialog box.
- Click the Items tab and click Add.
- Scroll to the Map Navigation category (you can select different types of commands to be included on the toolbar). See the following screen shot:
- In the preceding screen shot, you can double-click individual commands or a category to add them to the toolbar. You can also highlight a command and click the Add Command button to add it separately. For now, choose several items to add and click Close; all the items appear in the Java Property Editor (you can also remove added items). See the following screen shot:
- Right-click an item that you want to remove and click Delete. You can also begin a toolbar group or show text instead of the icon on the toolbar. Leave the Image Only option selected to show the icons. See the following screen shot:
- Click OK when you are finished setting up the toolbar.
Completing the code and initializing the ArcGIS Engine license
You are almost ready to run your application. However, you must set an appropriate runtime license and make a few other additions to the code.
- Switch to the code view. In several places, some red underlined code is visible with a small red x on the left panel. Eclipse is showing that this item needs attention and it can be resolved by clicking the red x. See the following screen shot:
- Options to fix the code appear. Click Surround with try/catch to resolve the situation and to automatically insert the code. See the following screen shot:
Do this procedure for the TOC, toolbar, and map components where the red x appears.
- The ArcGIS Engine application needs to be properly licensed. A shortcut is available to create this code. Right-click in the code editor and click ArcGIS, Insert License Code. See the following screen shot:
- Select the ArcGIS Engine check box and click OK. See the following screen shot:
This code creates a new method to initialize the ArcGIS license check for the ArcGIS Engine product code. For more information regarding licensing and its uses, see Licensing and deployments.
- After creating the license method, call it within the main method of the application before it uses any ArcObjects. In the default constructor, add the following code example:
- Initialize the visual beans in the main method. In the public static void main method, type the following code example:
Create a new instance of the application and make it visible before running it. Type the following code example in the main method:
EngineApp map = new EngineApp(); map.setVisible(true);
- Save your project.
- Right-click EngineApp.java in the Package Explorer and click Run As and Java Application. See the following screen shot:
The application window appears with the specified toolbar and map items. See the following screen shot:
|Development licensing||Deployment licensing|
|Engine Developer Kit||Engine|