Flyingis

Talking and thinking freely !
Flying in the world of GIS !
随笔 - 156, 文章 - 16, 评论 - 589, 引用 - 0
数据加载中……

AE92 SDK for Java 窗体简例

    作者:Flyingis

    ArcEngine开发文档中提供了另外一个开发简例HelloGlobe,它是基于JFrame窗体的一个简单应用,从窗体设计代码中我们可以看到,ArcEngine已经以JavaBean的形式封装了一些常用的窗体控件,可以直接的应用到窗体设计的开发中,并且支持跨平台,给开发者提供了另一种选择。

    引用的包:

import java.awt.BorderLayout;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.IOException;
import javax.swing.JFrame;

import com.esri.arcgis.beans.TOC.TOCBean;
import com.esri.arcgis.beans.globe.GlobeBean;
import com.esri.arcgis.beans.toolbar.ToolbarBean;
import com.esri.arcgis.controls.ControlsGlobeFullExtentCommand;
import com.esri.arcgis.controls.ControlsGlobeNavigateTool;
import com.esri.arcgis.controls.ControlsGlobeOpenDocCommand;
import com.esri.arcgis.system.AoInitialize;
import com.esri.arcgis.system.EngineInitializer;
import com.esri.arcgis.system.esriLicenseExtensionCode;
import com.esri.arcgis.system.esriLicenseProductCode;

    关于AWT和Swing的使用可以参考相关的书籍,从引用的包中,可以看到TOC、toolbar、globe显示窗都已经封装到JavaBean中,可以直接调用,为开发者省了不少事,也帮助开发人员可以像在Visual Studio下设计UI一样来设计Java的窗体。

    看看它的窗体设计代码:

//
// Create and display the frame
//
private void display() throws IOException {
  setSize(
500400);
  
//
  
// Create the globe, toolbar, and table of contents beans.
  
//
  GlobeBean globeBean = new GlobeBean();
  ToolbarBean toolbarBean 
= new ToolbarBean();
  TOCBean tocBean 
= new TOCBean();
  
//
  
// Add beans to the content pane.
  
//
  getContentPane().add(toolbarBean, BorderLayout.NORTH);
  getContentPane().add(globeBean, BorderLayout.CENTER);
  getContentPane().add(tocBean, BorderLayout.WEST);
  
//
  
// Add commands and tool to the toolbar.
  
//
  toolbarBean.addItem(new ControlsGlobeOpenDocCommand(), 0-1false01);
  toolbarBean.addItem(
new ControlsGlobeNavigateTool(), 0-1false01);
  toolbarBean.addItem(
new ControlsGlobeFullExtentCommand(), 0-1false01);
  
//
  
// Buddy up the globe with the toolbar and table of contents.
  
//
  toolbarBean.setBuddyControl(globeBean);
  tocBean.setBuddyControl(globeBean);
  
//
  
// Shutdown ArcObjects when the window closes.
  
//
  addWindowListener(new WindowAdapter() {
    
public void windowClosing(WindowEvent e) {
      
try {
        
new AoInitialize().shutdown();
        System.exit(
0);
      }

      
catch (IOException ex) {
        System.out.println(ex.getMessage());
        System.exit(
1);
      }

    }

  }
);
  setVisible(
true);
}

    纯粹的Java窗体设计风格,简单易用。再看看main方法中的内容,和前面一篇《AE92 SDK for Java 最小示例学习》稍有区别。

    main方法:

public static void main(String args[]) {
  
try {
    EngineInitializer.initializeVisualBeans();            
    AoInitialize aoInitializer 
= new AoInitialize();
    aoInitializer.initialize(esriLicenseProductCode.esriLicenseProductCodeEngine);
    aoInitializer.checkOutExtension(esriLicenseExtensionCode.esriLicenseExtensionCode3DAnalyst);
    HelloGlobe thisApp 
= new HelloGlobe();
    thisApp.setTitle(
"Hello, Globe!");
    thisApp.display();
  }

  
catch (IOException ex) {
    System.out.println(ex.getMessage());
  }

}

    由于应用程序使用了窗体,因此在原始AO组建和Java Class建立关联时,需要initializeVisualBeans方法来初始化,initializeVisualBeans和initializeEngine两者选其一,使用可视化Beans选择前者,否则选择后者。这里aoInitializer对象除了指定相应的license授权,还检查相应的应用扩展。

    AE92 SDK for Java 已经集成到Eclipse3.2中,通过ArcEngine模板建立一个HelloGlobe工程,看看运行显示的结果:

HelloGlobe.gif

    基于这个模板框架,可以方便我们深入扩展Globe二次开发的功能。

posted on 2007-03-09 12:41 Flyingis 阅读(4914) 评论(2)  编辑  收藏 所属分类: ArcEngine

评论

# re: AE92 SDK for Java 窗体简例[未登录]  回复  更多评论   

怎么设置toolbar的tip,我添加上toolbar后里面的按钮全是英文的,怎么修改成中文?
2008-01-10 09:20 | 王飞

# re: AE92 SDK for Java 窗体简例  回复  更多评论   

ArcGIS Engine JAVA qq群: 24450639
2009-02-22 17:49 | leagion

只有注册用户登录后才能发表评论。


网站导航: