package com.suncreate.bean;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.Insets;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.ArrayList;
import java.util.HashMap;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTree;
import javax.swing.border.EtchedBorder;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.TableModel;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreePath;
import com.suncreate.MainUI;
import com.suncreate.bean.query.Page;
import com.suncreate.bean.query.Query;
import com.suncreate.bean.query.QueryResult;
import com.suncreate.resources.Resources;
import com.suncreate.resources.icons.Icon;
@SuppressWarnings("serial")
public class QueryResultPanelBean extends JPanel {
private MainUI mainUI = null;
// 结果显示面板
private JPanel resultPanel = null;
// 图层定位层列表
private JComboBox layerList = null;
// 定位Button
private JButton goToButtom = null;
// 详细信息Button
private JButton detailInfoBtn = null;
// 结果集
private ArrayList<QueryResult> queryResults = new ArrayList<QueryResult>();
// 结果显示树
private JTree tree = null;
// 树Model
private DefaultTreeModel model = null;
// 树根
private DefaultMutableTreeNode root = null;
// 用于暂时存放FID
private HashMap<String, String> hashMap = new HashMap<String, String>();
// 分页
private Page page = null;
// 当前页
private JLabel currentPageLabel = null;
// 总页数
private JLabel totalPageLabel = null;
// 关闭按钮
private JButton shutbutton = null;
private JPanel toppanel = null;
public QueryResultPanelBean(MainUI mainUI) {
this.mainUI = mainUI;
buildAndShow();
}
public void buildAndShow() {
BorderLayout borderLayout = new BorderLayout();
this.setLayout(borderLayout);
Dimension dimension = new Dimension();
dimension.setSize(200, 2000);
this.setPreferredSize(dimension);
// 地图查询结果列表
JLabel title = new JLabel();
title.setText(Resources.getResourceText("QueryResultTitle"));
// 结果显示面板
resultPanel = new JPanel();
resultPanel.setLayout(new BorderLayout());
resultPanel.setBorder(BorderFactory
.createEtchedBorder(EtchedBorder.LOWERED));
JPanel resultPanelTop = new JPanel();
resultPanelTop.setLayout(new GridLayout(1, 2));
JLabel layerGoTo = new JLabel(Resources.getResourceText("LayerGoTo"));
layerList = new JComboBox();
layerList.addItem("********************");
layerList.setBorder(BorderFactory.createLoweredBevelBorder());
layerList.setBackground(Color.WHITE);
layerList.setPreferredSize(new Dimension(25, 25));
resultPanelTop.add(layerGoTo);
resultPanelTop.add(layerList);
// 查询结果显示
root = new DefaultMutableTreeNode(Resources
.getResourceText("ResultRoot"));
model = new DefaultTreeModel(root);
tree = new JTree(model);
tree.setRootVisible(false);
JScrollPane resultScrollPane = new JScrollPane(tree);
resultScrollPane.setBorder(BorderFactory.createLoweredBevelBorder());
resultScrollPane.setBackground(Color.WHITE);
// 结果列表下边的面板
JPanel navPanel = new JPanel();
navPanel.setLayout(new BorderLayout());
// 定位和详细信息Buttom
JPanel goToAndDetailPanel = new JPanel();
goToAndDetailPanel.setLayout(new GridLayout(1, 2, 10, 10));
goToAndDetailPanel.add(goToButtom = new JButton(Resources
.getResourceText("GotoButtom")));
goToAndDetailPanel.add(detailInfoBtn = new JButton(Resources
.getResourceText("DetailInfo")));
goToButtom.setForeground(Color.blue);
// 分页
JPanel pagePanel = new JPanel();
page = new Page(this);
// 动态改变按钮的大小
page.getFirstPageBtn().setMargin(new Insets(0, 1, 0, 1));
page.getFirstPageBtn().setForeground(Color.red);
pagePanel.add(page.getFirstPageBtn());
page.getPrePageBtn().setMargin(new Insets(0, 1, 0, 1));
pagePanel.add(page.getPrePageBtn());
pagePanel.add(new JLabel(Resources.getResourceText("Di")));
pagePanel.add(currentPageLabel = new JLabel("0"));
pagePanel.add(new JLabel(Resources.getResourceText("Ye")));
page.getNextPageBtn().setMargin(new Insets(0, 1, 0, 1));
pagePanel.add(page.getNextPageBtn());
page.getEndPageBtn().setMargin(new Insets(0, 1, 0, 1));
page.getEndPageBtn().setForeground(Color.red);
pagePanel.add(page.getEndPageBtn());
pagePanel.add(new JLabel(Resources.getResourceText("Gong")));
pagePanel.add(totalPageLabel = new JLabel("0"));
pagePanel.add(new JLabel(Resources.getResourceText("Ye")));
navPanel.add(goToAndDetailPanel, BorderLayout.NORTH);
navPanel.add(pagePanel, BorderLayout.CENTER);
resultPanel.add(resultPanelTop, BorderLayout.NORTH);
resultPanel.add(resultScrollPane, BorderLayout.CENTER);
resultPanel.add(navPanel, BorderLayout.SOUTH);
shutbutton = new JButton(new ImageIcon(Resources.getIcon(Icon.class,
"generic/editcut.gif")));
// 按钮的动态缩放
shutbutton.setMargin(new Insets(0, 0, 0, 0));
shutbutton.setBorder(null);
toppanel = new JPanel();
toppanel.setLayout(new BorderLayout());
toppanel.add(shutbutton, BorderLayout.EAST);
toppanel.add(title, BorderLayout.WEST);
this.add(toppanel, BorderLayout.NORTH);
this.add(resultPanel, BorderLayout.CENTER);
addListener();
}
public ArrayList<QueryResult> getQueryResults() {
return queryResults;
}
public void setQueryResults(ArrayList<QueryResult> queryResults) {
this.queryResults = queryResults;
}
public void showResult() {
try {
clearResult();
// 确认总的结果数
page.setTotalCount(queryResults.size());
for (int i = 0; i < page.getCurrentPageResultNumber(); i++) {
// 获得结果
int resultIndex = page.getCurrentPageNumber()
* page.getPageByCount() + i;
QueryResult result = queryResults.get(resultIndex);
// 获得当前结果的图层名称
String layerName = result.getFeatureLayer().getName();
// 新建叶子节点,该叶子节点就是我们的特征元素\
int k = 2;
String featureName = "***********";
for (; k < result.getFields().getFieldCount(); k++) {
if (result.getFields().getField(k).getName()
.equalsIgnoreCase("name")) {
if (!((String) result.getFeature().getValue(k)).trim()
.equals("")) {
featureName = (String) result.getFeature()
.getValue(k);
}
}
}
DefaultMutableTreeNode featureNode = new DefaultMutableTreeNode(
featureName);
// 获取当前特征元素的FID
String FID = result.getFeature().getValue(0).toString();
// 生成HashMap中的Key
String FIDkey = "";
// 获得特征元素的Index号
int featureIndex = 0;
/**
* 判断Root根是否有子节点,如果没有子节点直接把图层名加到树根上面;
* 如果有子节点,获取Root的最后一个子节点的名称,和当前layerName进行比较,
* 如果相等表示当前图层在Root上面已经存在
*/
if (root.isLeaf()) {
// 当前Root没有子节点
// 创建层结点
DefaultMutableTreeNode layerNode = new DefaultMutableTreeNode(
layerName);
// 直接把特征元素加入到层结点
layerNode.add(featureNode);
// 把层结点加入根结点
root.add(layerNode);
// 把图层添加到下拉列表中去
layerList.addItem(layerNode);
featureIndex = layerNode.getIndex(featureNode);
FIDkey = layerName + String.valu
- 1
- 2
前往页