📄 addressmatchsample.java
字号:
package com.supermap.samplecodes.addressmatchsample;
import javax.swing.*;
import java.awt.*;
import com.supermap.ui.MapControl;
import java.awt.Toolkit;
import java.awt.event.*;
import com.supermap.data.*;
import com.supermap.mapping.*;
import java.net.URL;
import java.awt.Rectangle;
import com.supermap.ui.Action;
import javax.swing.JButton;
import java.awt.Rectangle;
import javax.swing.JTextField;
import java.awt.Toolkit;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import com.supermap.data.WorkspaceConnectionInfo;
import javax.swing.JOptionPane;
import com.supermap.data.WorkspaceType;
import com.supermap.data.Workspace;
import java.io.File;
import com.supermap.analyst.spatialanalyst.AddressDictionary;
import java.awt.event.WindowEvent;
import java.awt.event.WindowAdapter;
import com.supermap.data.Recordset;
import com.supermap.data.Datasources;
import com.supermap.data.Datasource;
import com.supermap.data.Datasets;
import com.supermap.data.Dataset;
import com.supermap.data.DatasetType;
import com.supermap.data.DatasetVector;
import com.supermap.data.CursorType;
import com.supermap.analyst.spatialanalyst.AddressMatchParameter;
import com.supermap.analyst.spatialanalyst.AddressMatchResults;
import com.supermap.analyst.spatialanalyst.AddressMatchSetting;
import com.supermap.analyst.spatialanalyst.AddressMatch;
import com.supermap.mapping.Map;
import com.supermap.mapping.Layer;
import java.io.*;
import com.supermap.ui.MapControl;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTable;
import java.awt.BorderLayout;
import javax.swing.table.DefaultTableModel;
import java.awt.event.MouseEvent;
import java.awt.event.MouseAdapter;
import com.supermap.mapping.Selection;
import javax.swing.ListSelectionModel;
import javax.swing.table.TableCellEditor;
import java.util.EventObject;
import java.awt.Component;
import javax.swing.AbstractCellEditor;
import java.awt.Cursor;
/**
* <p>Title:中文地址匹配 </p>
*
* <p>Description:
* ============================================================================>
* ------------------------------版权声明----------------------------
* 此文件为 SuperMap Objects Java 的示范代码
* 版权所有:北京超图软件股份有限公司
* ------------------------------------------------------------------
* ---------------------SuperMap Objects Java 示范程序说明------------------------
*
* 1、范例简介:中文地址匹配,制作词典,匹配数据,并分析显示结果数据
* 2、示例数据:安装目录\SampleData\world\world.sxw;
* 3、关键类型/成员:
* AddressDictionary的Load(),saveAs(),contains方法
* AddressMatch的match()方法;
* AddressMatchParameter的addSearchDataset()方法;
* AddressMatchResult的相关方法
* AddressMatchSetting的addSearchData()方法;
* 数据集查询记录集以及获取字段的相关方法;
* MapColtrol的相关方法
* 4、使用步骤:
* (1)单击“打开地图”按钮,打开指定工作空间的指定地图;
* (2)点击"导入数据内所有记录"按钮,在指定的词典内(如果不存在则创建一个词典)导入数据内所有中文记录;
* (3)在搜索框内输入要搜索的字段,单击按钮"GO",在下面的图层内显示出搜到的内容,输出相关
* 搜索信息。
* (4)点击搜索信息在地图中高亮显示
* ------------------------------------------------------------------------------
* ============================================================================>
* </p>
*
* <p>Copyright: Copyright (c) 2008</p>
*
* <p>Company:北京超图软件股份有限公司</p>
*
* @author SuperMap GIS
* @version 2.0
*/
public class AddressMatchSample extends JFrame {
Workspace workspace = null;
MapControl mapControl = new MapControl();
public AddressMatchSample() {
try {
this.setSize(850, 500);
this.setResizable(false);
// Center the window
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = this.getSize();
if (frameSize.height > screenSize.height) {
frameSize.height = screenSize.height;
}
if (frameSize.width > screenSize.width) {
frameSize.width = screenSize.width;
}
this.setLocation((screenSize.width - frameSize.width) / 2,
(screenSize.height - frameSize.height) / 2);
initActionButtonIcon();
jbInit();
} catch (Exception ex) {
ex.printStackTrace();
}
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
// try {
// UIManager.setLookAndFeel(UIManager.
// getSystemLookAndFeelClassName());
// } catch (Exception exception) {
// exception.printStackTrace();
// }
AddressMatchSample mapSample = new AddressMatchSample();
mapSample.setVisible(true);
}
});
}
//对Action按钮初始化其Icon
private void initActionButtonIcon() {
URL url = getClass().getResource("MapAction\\action_select.png");
ImageIcon iconSelect = new ImageIcon(url);
btnSelect.setIcon(iconSelect);
url = getClass().getResource("MapAction\\action_pan.png");
ImageIcon iconPan = new ImageIcon(url);
btnPan.setIcon(iconPan);
url = getClass().getResource("MapAction\\action_zoomin.png");
ImageIcon iconZoomIn = new ImageIcon(url);
btnZoomIn.setIcon(iconZoomIn);
url = getClass().getResource("MapAction\\action_zoomout.png");
ImageIcon iconZoomOut = new ImageIcon(url);
btnZoomOut.setIcon(iconZoomOut);
url = getClass().getResource("MapAction\\action_zoomfree.png");
ImageIcon iconFree = new ImageIcon(url);
btnFree.setIcon(iconFree);
url = getClass().getResource("MapAction\\action_viewentire.png");
ImageIcon iconViewEntire = new ImageIcon(url);
btnViewEntire.setIcon(iconViewEntire);
url = getClass().getResource("MapAction\\action_refresh.png");
ImageIcon iconRefresh = new ImageIcon(url);
btnRefresh.setIcon(iconRefresh);
}
private void jbInit() throws Exception {
this.setTitle("中文地址匹配");
this.addWindowListener(new AddressMatchSample_this_windowAdapter(this));
btnOpenMap.setBounds(new Rectangle(10, 10, 103, 35));
btnOpenMap.setText("打开地图");
btnOpenMap.addActionListener(new
AddressMatchSample_btnOpenMap_actionAdapter(this));
this.getContentPane().setLayout(null);
panelAction.setLayout(null);
btnPan.setBounds(new Rectangle(43, 4, 40, 35));
btnPan.addActionListener(new AddressMatchSample_btnPan_actionAdapter(this));
btnSelect.setBounds(new Rectangle(3, 4, 41, 35));
btnSelect.addActionListener(new
AddressMatchSample_btnSelect_actionAdapter(this));
btnZoomIn.setBounds(new Rectangle(82, 4, 40, 35));
btnZoomIn.addActionListener(new
AddressMatchSample_btnZoomIn_actionAdapter(this));
btnZoomOut.setBounds(new Rectangle(121, 4, 40, 35));
btnZoomOut.addActionListener(new
AddressMatchSample_btnZoomOut_actionAdapter(this));
btnFree.setBounds(new Rectangle(160, 4, 40, 35));
btnFree.addActionListener(new AddressMatchSample_btnFree_actionAdapter(this));
btnViewEntire.setBounds(new Rectangle(201, 4, 38, 35));
btnViewEntire.addActionListener(new
AddressMatchSample_btnViewEntire_actionAdapter(this));
btnRefresh.setBounds(new Rectangle(239, 4, 38, 35));
btnRefresh.addActionListener(new
AddressMatchSample_btnRefresh_actionAdapter(this));
mapControl.setBounds(new Rectangle(10, 58, 586, 407));
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
btnClose.setBounds(new Rectangle(442, 10, 80, 35));
btnClose.setText("关闭");
btnClose.addActionListener(new
AddressMatchSample_btnClose_actionAdapter(this));
btnAdd.setBounds(new Rectangle(598, 82, 231, 27));
btnAdd.setEnabled(false);
btnAdd.setText("导入数据内所有记录");
btnAdd.addActionListener(new AddressMatchSample_btnAdd_actionAdapter(this));
textSearch.setEnabled(false);
textSearch.setToolTipText("输入搜索内容");
textSearch.setBounds(new Rectangle(663, 127, 165, 27));
btnGO.setBounds(new Rectangle(598, 127, 55, 27));
btnGO.setEnabled(false);
btnGO.setText("GO");
btnGO.addActionListener(new AddressMatchSample_btnGO_actionAdapter(this));
jScrollPane1.setBounds(new Rectangle(598, 200, 231, 216));
panelAction.add(btnSelect);
panelAction.add(btnPan);
panelAction.add(btnZoomIn);
panelAction.add(btnZoomOut);
panelAction.add(btnViewEntire);
panelAction.add(btnRefresh);
panelAction.add(btnFree);
String[] Names = {"数据集", "ID", "查询字段", "分数"};
Object[][] objects = {};
defaultTableMode = new DefaultTableModel(objects, Names);
tableResult = new JTable(defaultTableMode);
//设置表为单选
tableResult.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
//设置表不可编辑
for (int i = 0; i < tableResult.getColumnCount(); i++) {
tableResult.getColumnModel().getColumn(i).setCellEditor(new
TableColumnEditorLocked());
}
//使表格不可整列移动
tableResult.getTableHeader().setReorderingAllowed(false);
tableResult.addMouseListener(new
AddressMatchFrame_tableResult_mouseAdapter(this));
this.getContentPane().add(btnAdd);
this.getContentPane().add(btnGO);
this.getContentPane().add(textSearch);
this.getContentPane().add(btnClose);
this.getContentPane().add(mapControl);
this.getContentPane().add(btnOpenMap, null);
this.getContentPane().add(panelAction);
this.getContentPane().add(jScrollPane1);
panelAction.setBorder(BorderFactory.createEtchedBorder());
panelAction.setBounds(new Rectangle(119, 6, 283, 44));
jScrollPane1.getViewport().add(tableResult);
}
JButton btnOpenMap = new JButton();
JPanel panelAction = new JPanel();
JButton btnPan = new JButton();
JButton btnSelect = new JButton();
JButton btnZoomIn = new JButton();
JButton btnZoomOut = new JButton();
JButton btnFree = new JButton();
JButton btnViewEntire = new JButton();
JButton btnRefresh = new JButton();
JButton btnClose = new JButton();
JButton btnAdd = new JButton();
JTextField textSearch = new JTextField();
JButton btnGO = new JButton();
JScrollPane jScrollPane1 = new JScrollPane();
//定义中文地址模糊匹配类
AddressMatch addressmatch ;
//获取AddressMatchSetting并进行相关设置
AddressMatchSetting addressmatchsetting ;
//定义中文地址模糊匹配参数类。
AddressMatchParameter addressmatchparameter;
DatasetVector[] dd;
AddressDictionary addressDictionary ;
DefaultTableModel defaultTableMode;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -