MapPanel.java
上传用户:njlgjx
上传日期:2022-08-07
资源大小:9105k
文件大小:31k
源码类别:

图形图象

开发平台:

Java

  1. /*
  2.  * MapPanel.java
  3.  *
  4.  * Created on 2008年6月24日, 下午2:54
  5.  */
  6. package com.mwq.map;
  7. import com.mwq.map.frame.ProgressBarDialog;
  8. import com.mwq.map.frame.ManageSignDialog;
  9. import com.mwq.map.frame.AdvancedSearchDialog;
  10. import com.mwq.map.frame.ShowSignDialog;
  11. import com.mwq.map.dao.Dao;
  12. import com.mwq.map.frame.ManageSortDialog;
  13. import com.mwq.map.tool.InstancePool;
  14. import java.io.File;
  15. import java.io.FileInputStream;
  16. import java.io.FileOutputStream;
  17. import java.io.InputStream;
  18. import java.io.OutputStream;
  19. import java.util.Vector;
  20. import java.util.logging.Level;
  21. import java.util.logging.Logger;
  22. import javax.swing.JFileChooser;
  23. import javax.swing.JOptionPane;
  24. import javax.swing.filechooser.FileFilter;
  25. import com.mwq.map.tool.MapProcessor;
  26. import java.awt.Cursor;
  27. import java.awt.event.KeyEvent;
  28. import java.awt.event.MouseEvent;
  29. import javax.swing.ImageIcon;
  30. import javax.swing.SwingUtilities;
  31. /**
  32.  *
  33.  * @author  Administrator
  34.  */
  35. public class MapPanel extends javax.swing.JPanel {
  36.     private Dao dao = Dao.getInstance();
  37.     private MapProcessor mapProcessor;
  38.     /** Creates new form MapPanel */
  39.     public MapPanel() {
  40.         initComponents();
  41.     }
  42.     public MapProcessor getMapProcessor() {
  43.         return mapProcessor;
  44.     }
  45.     /** This method is called from within the constructor to
  46.      * initialize the form.
  47.      * WARNING: Do NOT modify this code. The content of this method is
  48.      * always regenerated by the Form Editor.
  49.      */
  50.     @SuppressWarnings("unchecked")
  51.     // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
  52.     private void initComponents() {
  53.         java.awt.GridBagConstraints gridBagConstraints;
  54.         signPopupMenu = new javax.swing.JPopupMenu();
  55.         showMenuItem = new javax.swing.JMenuItem();
  56.         separator = new javax.swing.JSeparator();
  57.         createMenuItem = new javax.swing.JMenuItem();
  58.         updateMenuItem = new javax.swing.JMenuItem();
  59.         deleteMenuItem = new javax.swing.JMenuItem();
  60.         leftPanel = new javax.swing.JPanel();
  61.         bigMapLabel = new com.mwq.map.mwing.BigMapLabel();
  62.         adjustMapPanel = new javax.swing.JPanel();
  63.         upButton = new javax.swing.JButton();
  64.         downButton = new javax.swing.JButton();
  65.         revertButton = new javax.swing.JButton();
  66.         leftButton = new javax.swing.JButton();
  67.         rightButton = new javax.swing.JButton();
  68.         subButton = new javax.swing.JButton();
  69.         addButton = new javax.swing.JButton();
  70.         slider = new javax.swing.JSlider();
  71.         rightPanel = new javax.swing.JPanel();
  72.         smallMapLabel = new com.mwq.map.mwing.SmallMapLabel();
  73.         searchPanel = new javax.swing.JPanel();
  74.         searchConditionPanel = new javax.swing.JPanel();
  75.         keywordTextField = new javax.swing.JTextField();
  76.         searchButtonPanel = new javax.swing.JPanel();
  77.         simpleButton = new javax.swing.JButton();
  78.         advancedButton = new javax.swing.JButton();
  79.         searchResultScrollPane = new javax.swing.JScrollPane();
  80.         searchResultList = new javax.swing.JList();
  81.         managePanel = new javax.swing.JPanel();
  82.         manageSortButton = new javax.swing.JButton();
  83.         setMapButton = new javax.swing.JButton();
  84.         showMenuItem.setText("查看信息");
  85.         showMenuItem.addActionListener(new java.awt.event.ActionListener() {
  86.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  87.                 showMenuItemActionPerformed(evt);
  88.             }
  89.         });
  90.         signPopupMenu.add(showMenuItem);
  91.         signPopupMenu.add(separator);
  92.         createMenuItem.setText("创建标记");
  93.         createMenuItem.addActionListener(new java.awt.event.ActionListener() {
  94.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  95.                 createMenuItemActionPerformed(evt);
  96.             }
  97.         });
  98.         signPopupMenu.add(createMenuItem);
  99.         updateMenuItem.setText("修改标记");
  100.         updateMenuItem.addActionListener(new java.awt.event.ActionListener() {
  101.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  102.                 updateMenuItemActionPerformed(evt);
  103.             }
  104.         });
  105.         signPopupMenu.add(updateMenuItem);
  106.         deleteMenuItem.setText("删除标记");
  107.         deleteMenuItem.addActionListener(new java.awt.event.ActionListener() {
  108.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  109.                 deleteMenuItemActionPerformed(evt);
  110.             }
  111.         });
  112.         signPopupMenu.add(deleteMenuItem);
  113.         setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
  114.         addComponentListener(new java.awt.event.ComponentAdapter() {
  115.             public void componentResized(java.awt.event.ComponentEvent evt) {
  116.                 formComponentResized(evt);
  117.             }
  118.         });
  119.         setLayout(new java.awt.BorderLayout());
  120.         leftPanel.setLayout(new java.awt.BorderLayout());
  121.         bigMapLabel.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
  122.         bigMapLabel.addMouseListener(new java.awt.event.MouseAdapter() {
  123.             public void mouseClicked(java.awt.event.MouseEvent evt) {
  124.                 bigMapLabelMouseClicked(evt);
  125.             }
  126.         });
  127.         bigMapLabel.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
  128.             public void mouseMoved(java.awt.event.MouseEvent evt) {
  129.                 bigMapLabelMouseMoved(evt);
  130.             }
  131.         });
  132.         leftPanel.add(bigMapLabel, java.awt.BorderLayout.CENTER);
  133.         adjustMapPanel.setLayout(new java.awt.GridBagLayout());
  134.         upButton.setText("▲");
  135.         upButton.addActionListener(new java.awt.event.ActionListener() {
  136.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  137.                 upButtonActionPerformed(evt);
  138.             }
  139.         });
  140.         gridBagConstraints = new java.awt.GridBagConstraints();
  141.         gridBagConstraints.gridx = 4;
  142.         gridBagConstraints.gridy = 0;
  143.         gridBagConstraints.insets = new java.awt.Insets(5, 0, 0, 0);
  144.         adjustMapPanel.add(upButton, gridBagConstraints);
  145.         downButton.setText("▼");
  146.         downButton.addActionListener(new java.awt.event.ActionListener() {
  147.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  148.                 downButtonActionPerformed(evt);
  149.             }
  150.         });
  151.         gridBagConstraints = new java.awt.GridBagConstraints();
  152.         gridBagConstraints.gridx = 4;
  153.         gridBagConstraints.gridy = 2;
  154.         gridBagConstraints.insets = new java.awt.Insets(0, 0, 5, 0);
  155.         adjustMapPanel.add(downButton, gridBagConstraints);
  156.         revertButton.setText("■");
  157.         revertButton.addActionListener(new java.awt.event.ActionListener() {
  158.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  159.                 revertButtonActionPerformed(evt);
  160.             }
  161.         });
  162.         gridBagConstraints = new java.awt.GridBagConstraints();
  163.         gridBagConstraints.gridx = 4;
  164.         gridBagConstraints.gridy = 1;
  165.         gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
  166.         adjustMapPanel.add(revertButton, gridBagConstraints);
  167.         leftButton.setText("<");
  168.         leftButton.addActionListener(new java.awt.event.ActionListener() {
  169.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  170.                 leftButtonActionPerformed(evt);
  171.             }
  172.         });
  173.         gridBagConstraints = new java.awt.GridBagConstraints();
  174.         gridBagConstraints.gridx = 3;
  175.         gridBagConstraints.gridy = 1;
  176.         gridBagConstraints.insets = new java.awt.Insets(0, 40, 0, 0);
  177.         adjustMapPanel.add(leftButton, gridBagConstraints);
  178.         rightButton.setText(">");
  179.         rightButton.addActionListener(new java.awt.event.ActionListener() {
  180.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  181.                 rightButtonActionPerformed(evt);
  182.             }
  183.         });
  184.         gridBagConstraints = new java.awt.GridBagConstraints();
  185.         gridBagConstraints.gridx = 5;
  186.         gridBagConstraints.gridy = 1;
  187.         gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 20);
  188.         adjustMapPanel.add(rightButton, gridBagConstraints);
  189.         subButton.setText("-");
  190.         subButton.addActionListener(new java.awt.event.ActionListener() {
  191.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  192.                 subButtonActionPerformed(evt);
  193.             }
  194.         });
  195.         gridBagConstraints = new java.awt.GridBagConstraints();
  196.         gridBagConstraints.gridx = 0;
  197.         gridBagConstraints.gridy = 1;
  198.         gridBagConstraints.insets = new java.awt.Insets(0, 20, 0, 0);
  199.         adjustMapPanel.add(subButton, gridBagConstraints);
  200.         addButton.setText("+");
  201.         addButton.addActionListener(new java.awt.event.ActionListener() {
  202.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  203.                 addButtonActionPerformed(evt);
  204.             }
  205.         });
  206.         gridBagConstraints = new java.awt.GridBagConstraints();
  207.         gridBagConstraints.gridx = 2;
  208.         gridBagConstraints.gridy = 1;
  209.         adjustMapPanel.add(addButton, gridBagConstraints);
  210.         slider.setMajorTickSpacing(50);
  211.         slider.setMaximum(300);
  212.         slider.setMinimum(-300);
  213.         slider.setMinorTickSpacing(25);
  214.         slider.setPaintTicks(true);
  215.         slider.setSnapToTicks(true);
  216.         slider.setValue(-250);
  217.         slider.addChangeListener(new javax.swing.event.ChangeListener() {
  218.             public void stateChanged(javax.swing.event.ChangeEvent evt) {
  219.                 sliderStateChanged(evt);
  220.             }
  221.         });
  222.         gridBagConstraints = new java.awt.GridBagConstraints();
  223.         gridBagConstraints.gridx = 1;
  224.         gridBagConstraints.gridy = 1;
  225.         gridBagConstraints.insets = new java.awt.Insets(0, 5, 0, 5);
  226.         adjustMapPanel.add(slider, gridBagConstraints);
  227.         leftPanel.add(adjustMapPanel, java.awt.BorderLayout.SOUTH);
  228.         add(leftPanel, java.awt.BorderLayout.CENTER);
  229.         rightPanel.setLayout(new java.awt.BorderLayout());
  230.         smallMapLabel.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
  231.         smallMapLabel.setPreferredSize(new java.awt.Dimension(200, 200));
  232.         rightPanel.add(smallMapLabel, java.awt.BorderLayout.NORTH);
  233.         searchPanel.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
  234.         searchPanel.setLayout(new java.awt.BorderLayout());
  235.         searchConditionPanel.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
  236.         searchConditionPanel.setLayout(new javax.swing.BoxLayout(searchConditionPanel, javax.swing.BoxLayout.Y_AXIS));
  237.         keywordTextField.addKeyListener(new java.awt.event.KeyAdapter() {
  238.             public void keyReleased(java.awt.event.KeyEvent evt) {
  239.                 keywordTextFieldKeyReleased(evt);
  240.             }
  241.         });
  242.         searchConditionPanel.add(keywordTextField);
  243.         simpleButton.setText("搜索");
  244.         simpleButton.addActionListener(new java.awt.event.ActionListener() {
  245.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  246.                 simpleButtonActionPerformed(evt);
  247.             }
  248.         });
  249.         searchButtonPanel.add(simpleButton);
  250.         advancedButton.setText("高级");
  251.         advancedButton.addActionListener(new java.awt.event.ActionListener() {
  252.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  253.                 advancedButtonActionPerformed(evt);
  254.             }
  255.         });
  256.         searchButtonPanel.add(advancedButton);
  257.         searchConditionPanel.add(searchButtonPanel);
  258.         searchPanel.add(searchConditionPanel, java.awt.BorderLayout.NORTH);
  259.         searchResultList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
  260.         searchResultList.setFixedCellWidth(20);
  261.         searchResultList.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
  262.             public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
  263.                 searchResultListValueChanged(evt);
  264.             }
  265.         });
  266.         searchResultScrollPane.setViewportView(searchResultList);
  267.         searchPanel.add(searchResultScrollPane, java.awt.BorderLayout.CENTER);
  268.         rightPanel.add(searchPanel, java.awt.BorderLayout.CENTER);
  269.         managePanel.setPreferredSize(new java.awt.Dimension(0, 102));
  270.         managePanel.setLayout(new java.awt.GridLayout(1, 0));
  271.         manageSortButton.setText("维护类别");
  272.         manageSortButton.addActionListener(new java.awt.event.ActionListener() {
  273.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  274.                 manageSortButtonActionPerformed(evt);
  275.             }
  276.         });
  277.         managePanel.add(manageSortButton);
  278.         setMapButton.setText("更换地图");
  279.         setMapButton.addActionListener(new java.awt.event.ActionListener() {
  280.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  281.                 setMapButtonActionPerformed(evt);
  282.             }
  283.         });
  284.         managePanel.add(setMapButton);
  285.         rightPanel.add(managePanel, java.awt.BorderLayout.SOUTH);
  286.         add(rightPanel, java.awt.BorderLayout.EAST);
  287.     }// </editor-fold>                        
  288. private void upButtonActionPerformed(java.awt.event.ActionEvent evt) {                                         
  289. // TODO add your handling code here:
  290.     bigMapLabel.setIcon(mapProcessor.moveOfVertical(-100));// 刷新地图显示区
  291.     //判断垂直移动按钮是否可用
  292.     if (!downButton.isEnabled()) {
  293.         downButton.setEnabled(true);
  294.     } else {
  295.         if (mapProcessor.getShowCenterY() - mapProcessor.getCutMapHeight() / 2 < 2) {
  296.             upButton.setEnabled(false);
  297.         }
  298.     }
  299.     SwingUtilities.updateComponentTreeUI(smallMapLabel);// 刷新鹰眼漫游区
  300. }                                        
  301. private void addButtonActionPerformed(java.awt.event.ActionEvent evt) {                                          
  302. // TODO add your handling code here:
  303.     slider.setValue(slider.getValue() + 25);// 将缩放比例增加一个单位
  304. }                                         
  305. private void setMapButtonActionPerformed(java.awt.event.ActionEvent evt) {                                             
  306. // TODO add your handling code here:
  307.     int showConfirmDialog = JOptionPane.showConfirmDialog(MapPanel.this, "确定要更换地图?", "友情提示", JOptionPane.YES_NO_OPTION);
  308.     if (showConfirmDialog == 0) {
  309.         JFileChooser fileChooser = new JFileChooser();
  310.         fileChooser.setFileFilter(new FileFilter() {
  311.             @Override
  312.             public boolean accept(File file) {
  313.                 if (file.isDirectory()) {
  314.                     return true;
  315.                 } else {
  316.                     String fileName = file.getName().toUpperCase();
  317.                     if (fileName.endsWith(".JPG") || fileName.endsWith(".JPEG") || fileName.endsWith(".GIF")) {
  318.                         return true;
  319.                     } else {
  320.                         return false;
  321.                     }
  322.                 }
  323.             }
  324.             @Override
  325.             public String getDescription() {
  326.                 return "地图格式(.JPG;.JPEG;.GIF)";
  327.             }
  328.         });
  329.         if (fileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
  330.             String mapPath = this.getClass().getResource("/img/map").getPath();
  331.             new File(mapPath + "/" + dao.getMapName()).delete();
  332.             File selectedMapFile = fileChooser.getSelectedFile();
  333.             File upLoadFile = new File(mapPath + "/map" + selectedMapFile.getName().substring(selectedMapFile.getName().lastIndexOf(".")));
  334.             dao.setMapName(upLoadFile.getName());
  335.             try {
  336.                 InputStream inStream = new FileInputStream(selectedMapFile);
  337.                 OutputStream outStream = new FileOutputStream(upLoadFile);
  338.                 int readBytes = 0; // 读取字节数
  339.                 byte[] buffer = new byte[1024]; // 定义缓存数组
  340.                 while ((readBytes = inStream.read(buffer, 0, 1024)) != -1) {// 从输入流读取数据到缓存数组中
  341.                     outStream.write(buffer, 0, readBytes); // 将缓存数组中的数据输出到输出流
  342.                 }
  343.                 outStream.close();// 关闭输出流对象
  344.                 inStream.close();// 关闭输入流对象
  345.             } catch (Exception ex) {
  346.                 Logger.getLogger(MapPanel.class.getName()).log(Level.SEVERE, null, ex);
  347.             }
  348.             MapPanel.this.mapProcessor.replaceMap("/img/map/" + upLoadFile.getName());
  349.             slider.setValue(slider.getValue() + 1);
  350.             smallMapLabel.refreshScale();
  351.             smallMapLabel.setIcon(new ImageIcon(mapProcessor.zoom(200, 200)));
  352.         }
  353.     }
  354. }                                            
  355. private void subButtonActionPerformed(java.awt.event.ActionEvent evt) {                                          
  356. // TODO add your handling code here:
  357.     slider.setValue(slider.getValue() - 25);// 将缩放比例减小一个单位
  358. }                                         
  359. private void sliderStateChanged(javax.swing.event.ChangeEvent evt) {                                    
  360. // TODO add your handling code here:
  361.     int v = slider.getValue();// 获得划块的值
  362.     // 判断比例调整按钮是否可用
  363.     if (v == slider.getMinimum()) {// 调整为最小值
  364.         subButton.setEnabled(false);// 调小按钮不可用
  365.         if (!addButton.isEnabled()) {// 如果调大按钮不可用
  366.             addButton.setEnabled(true);// 设置调大按钮可用
  367.         }
  368.     } else if (v == slider.getMaximum()) {// 调整为最大值
  369.         addButton.setEnabled(false);// 调大按钮不可用
  370.         if (!subButton.isEnabled()) {// 如果调小按钮不可用
  371.             subButton.setEnabled(true);// 设置调小按钮可用
  372.         }
  373.     } else {
  374.         if (!subButton.isEnabled()) {// 如果调小按钮不可用
  375.             subButton.setEnabled(true);// 设置调小按钮可用
  376.         }
  377.         if (!addButton.isEnabled()) {// 如果调大按钮不可用
  378.             addButton.setEnabled(true);// 设置调大按钮可用
  379.         }
  380.     }
  381.     //刷新地图
  382.     bigMapLabel.setIcon(mapProcessor.adjustScale(v));// 重绘地图显示区
  383.     SwingUtilities.updateComponentTreeUI(smallMapLabel);// 重绘鹰眼漫游区
  384.     //判断水平移动按钮是否可用
  385.     int w = mapProcessor.getCutMapWidth() / 2;
  386.     if (mapProcessor.getShowCenterX() - w < 2 || mapProcessor.getMap().getWidth() - mapProcessor.getShowCenterX() - w < 2) {
  387.         if (mapProcessor.getShowCenterX() <= w) {
  388.             leftButton.setEnabled(false);
  389.         } else {
  390.             rightButton.setEnabled(false);
  391.         }
  392.     } else {
  393.         if (!leftButton.isEnabled()) {
  394.             leftButton.setEnabled(true);
  395.         }
  396.         if (!rightButton.isEnabled()) {
  397.             rightButton.setEnabled(true);
  398.         }
  399.     }
  400.     //判断垂直移动按钮是否可用
  401.     int h = mapProcessor.getCutMapHeight() / 2;
  402.     if (mapProcessor.getShowCenterY() - h < 2 || mapProcessor.getMap().getHeight() - mapProcessor.getShowCenterY() - h < 2) {
  403.         if (mapProcessor.getShowCenterY() <= h) {
  404.             upButton.setEnabled(false);
  405.         } else {
  406.             downButton.setEnabled(false);
  407.         }
  408.     } else {
  409.         if (!upButton.isEnabled()) {
  410.             upButton.setEnabled(true);
  411.         }
  412.         if (!downButton.isEnabled()) {
  413.             downButton.setEnabled(true);
  414.         }
  415.     }
  416. }                                   
  417. private void manageSortButtonActionPerformed(java.awt.event.ActionEvent evt) {                                                 
  418. // TODO add your handling code here:
  419.     new ManageSortDialog(null, true, slider, searchResultList).setVisible(true);
  420. }                                                
  421. private void formComponentResized(java.awt.event.ComponentEvent evt) {                                      
  422. // TODO add your handling code here:
  423.     if (mapProcessor == null) {
  424.         final ProgressBarDialog progressBarDialog = new ProgressBarDialog(null, true);
  425.         new Thread() {
  426.             @Override
  427.             public void run() {
  428.                 mapProcessor = new MapProcessor("/img/map/map.jpg", getBigMapLabel().getWidth(), getBigMapLabel().getHeight(), slider.getValue());
  429.                 InstancePool.setMapProcessor(mapProcessor);
  430.                 InstancePool.setScaleSlider(slider);
  431.                 getBigMapLabel().setIcon(mapProcessor.adjustWindow(getBigMapLabel().getWidth(), getBigMapLabel().getHeight()));
  432.                 smallMapLabel.setIcon(new ImageIcon(mapProcessor.zoom(200, 200)));
  433.                 progressBarDialog.dispose();
  434.             }
  435.         }.start();
  436.         progressBarDialog.setVisible(true);
  437.     } else {
  438.         getBigMapLabel().setIcon(mapProcessor.adjustWindow(getBigMapLabel().getWidth(), getBigMapLabel().getHeight()));
  439.         SwingUtilities.updateComponentTreeUI(smallMapLabel);
  440.     }
  441. }                                     
  442. private void downButtonActionPerformed(java.awt.event.ActionEvent evt) {                                           
  443. // TODO add your handling code here:    
  444.     getBigMapLabel().setIcon(mapProcessor.moveOfVertical(100));// 刷新地图显示区
  445.     if (!upButton.isEnabled()) {
  446.         upButton.setEnabled(true);
  447.     } else {
  448.         if (mapProcessor.getMap().getHeight() - mapProcessor.getShowCenterY() - mapProcessor.getCutMapHeight() / 2 < 2) {
  449.             downButton.setEnabled(false);
  450.         }
  451.     }
  452.     SwingUtilities.updateComponentTreeUI(smallMapLabel);// 刷新鹰眼漫游区
  453. }                                          
  454. private void leftButtonActionPerformed(java.awt.event.ActionEvent evt) {                                           
  455. // TODO add your handling code here:    
  456.     getBigMapLabel().setIcon(mapProcessor.moveOfHorizontal(-100));// 刷新地图显示区
  457.     //判断水平移动按钮是否可用
  458.     if (!rightButton.isEnabled()) {
  459.         rightButton.setEnabled(true);
  460.     } else {
  461.         if (mapProcessor.getShowCenterX() - mapProcessor.getCutMapWidth() / 2 < 2) {
  462.             leftButton.setEnabled(false);
  463.         }
  464.     }
  465.     SwingUtilities.updateComponentTreeUI(smallMapLabel);// 刷新鹰眼漫游区
  466. }                                          
  467. private void rightButtonActionPerformed(java.awt.event.ActionEvent evt) {                                            
  468. // TODO add your handling code here:    
  469.     getBigMapLabel().setIcon(mapProcessor.moveOfHorizontal(100));// 刷新地图显示区
  470.     if (!leftButton.isEnabled()) {
  471.         leftButton.setEnabled(true);
  472.     } else {
  473.         if (mapProcessor.getMap().getWidth() - mapProcessor.getShowCenterX() - mapProcessor.getCutMapWidth() / 2 < 2) {
  474.             rightButton.setEnabled(false);
  475.         }
  476.     }
  477.     SwingUtilities.updateComponentTreeUI(smallMapLabel);// 刷新鹰眼漫游区
  478. }                                           
  479. private void revertButtonActionPerformed(java.awt.event.ActionEvent evt) {                                             
  480. // TODO add your handling code here:    
  481.     mapProcessor.revert();// 还原为默认的视觉中心
  482.     slider.setValue(-250);// 还原为默认的缩放比例
  483.     // 如果用于移动地图的按钮不可用,则将其设为可用
  484.     if (!upButton.isEnabled()) {
  485.         upButton.setEnabled(true);
  486.     }
  487.     if (!downButton.isEnabled()) {
  488.         downButton.setEnabled(true);
  489.     }
  490.     if (!leftButton.isEnabled()) {
  491.         leftButton.setEnabled(true);
  492.     }
  493.     if (!rightButton.isEnabled()) {
  494.         rightButton.setEnabled(true);
  495.     }
  496. }                                            
  497. private void updateMenuItemActionPerformed(java.awt.event.ActionEvent evt) {                                               
  498. // TODO add your handling code here:
  499.     new ManageSignDialog(null, true, "修改标记").setVisible(true);// 显示修改标记对话框
  500. }                                              
  501. private void showMenuItemActionPerformed(java.awt.event.ActionEvent evt) {                                             
  502. // TODO add your handling code here:
  503.     new ShowSignDialog(null, true).setVisible(true);// 显示查看信息对话框
  504. }                                            
  505. private void deleteMenuItemActionPerformed(java.awt.event.ActionEvent evt) {                                               
  506. // TODO add your handling code here:
  507.     int i = JOptionPane.showConfirmDialog(this, "确定要删除该标记?", "友情提示",
  508.             JOptionPane.YES_NO_OPTION);// 弹出确认删除提示框
  509.     if (i == 0) {// 确认删除
  510.         bigMapLabel.removeSign();// 删除标记
  511.         SwingUtilities.updateComponentTreeUI(bigMapLabel);// 刷新地图显示区
  512.         dao.deleteClickSign(mapProcessor.getRightClickToMapX(),
  513.                 mapProcessor.getRightClickToMapY());// 从数据库中删除
  514.     }
  515. }                                              
  516. private void bigMapLabelMouseClicked(java.awt.event.MouseEvent evt) {                                         
  517. // TODO add your handling code here:
  518.     if (evt.getButton() == MouseEvent.BUTTON3) {// 查看是否是由单击鼠标右键触发
  519.         boolean isEnteredSign = true;// 默认为在标记之上
  520.         if (getCursor() == Cursor.getDefaultCursor()) {
  521.             isEnteredSign = false;// 未在标记之上
  522.         }
  523.         // 设置菜单项的可用性
  524.         showMenuItem.setEnabled(isEnteredSign);
  525.         createMenuItem.setEnabled(!isEnteredSign);
  526.         updateMenuItem.setEnabled(isEnteredSign);
  527.         deleteMenuItem.setEnabled(isEnteredSign);
  528.         signPopupMenu.show(bigMapLabel, evt.getX(), evt.getY());// 显示弹出菜单
  529.     }
  530. }                                        
  531. private void createMenuItemActionPerformed(java.awt.event.ActionEvent evt) {                                               
  532. // TODO add your handling code here:
  533.     if (dao.selectChildSortByFatherId(0).size() == 0) {// 尚未添加类别
  534.         JOptionPane.showMessageDialog(this, "请先添加标记类别!", "友情提示",
  535.                 JOptionPane.INFORMATION_MESSAGE, null);// 弹出提示框
  536.     } else {// 已经添加类别
  537.         new ManageSignDialog(null, true, "创建标记").setVisible(true);// 显示创建标记对话框
  538.     }
  539. }                                              
  540.     private Vector<Vector> searchResult = new Vector<Vector>();
  541. private void simpleButtonActionPerformed(java.awt.event.ActionEvent evt) {                                             
  542. // TODO add your handling code here:
  543.     String general = keywordTextField.getText().trim();// 获得搜索关键字
  544.     if (general.length() == 0) {// 为输入关键字
  545.         JOptionPane.showMessageDialog(null, "请输入搜索关键字!", "友情提示",
  546.                 JOptionPane.INFORMATION_MESSAGE);// 弹出提示框
  547.         return;
  548.     }
  549.     searchResult = dao.selectSimpleSign(general.replace(' ', '%'));// 查询所有符合条件的标记
  550.     if (searchResult.size() == 0) {// 不存在符合查询条件的标记
  551.         JOptionPane.showMessageDialog(null, "没有符合条件的标记!", "友情提示",
  552.                 JOptionPane.INFORMATION_MESSAGE);// 弹出提示框
  553.     } else {// 存在符合查询条件的标记
  554.         final String[] items = new String[searchResult.size()];// 创建一个数组对象
  555.         for (int i = 0; i < items.length; i++) {// 遍历符合条件的标记
  556.             items[i] = " " + (i + 1) + "、" + searchResult.get(i).get(4);// 初始化数组
  557.         }
  558.         searchResultList.setModel(new javax.swing.AbstractListModel() {// 为列表框设置模型
  559.             public int getSize() {
  560.                 return items.length;// 返回拥有选项的个数
  561.             }
  562.             public Object getElementAt(int i) {
  563.                 return items[i];// 返回指定选项
  564.             }
  565.         });
  566.     }
  567. }                                            
  568. //    private AdvancedSearchDialog dialog;
  569. private void advancedButtonActionPerformed(java.awt.event.ActionEvent evt) {                                               
  570. // TODO add your handling code here:
  571.     new AdvancedSearchDialog(null, true, searchResultList, searchResult).setVisible(true);
  572. }                                              
  573. private void searchResultListValueChanged(javax.swing.event.ListSelectionEvent evt) {                                              
  574. // TODO add your handling code here:
  575.     int selectedIndex = searchResultList.getSelectedIndex();// 获得选中项索引
  576.     Vector sign = searchResult.get(selectedIndex);// 获得选中项向量
  577.     mapProcessor.adjustShowCenter((Integer) sign.get(2), (Integer) sign.get(3));// 调整视觉中心
  578.     bigMapLabel.setStress((Integer) sign.get(0));// 设置为描红显示
  579.     //刷新地图
  580.     int sliderValue = slider.getValue();// 获得当前的缩放比例
  581.     int scaleValue = mapProcessor.parseScale((Double) sign.get(6));// 获得需要的缩放比例
  582.     if (sliderValue < scaleValue) {// 当前比例小于缩放比例
  583.         slider.setValue(scaleValue);
  584.     } else {// 当前比例不小于缩放比例
  585.         slider.setValue(sliderValue + 1);
  586.     }
  587. }                                             
  588. private void keywordTextFieldKeyReleased(java.awt.event.KeyEvent evt) {                                             
  589. // TODO add your handling code here:
  590.     if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
  591.         simpleButtonActionPerformed(null);
  592.     }
  593. }                                            
  594. private void bigMapLabelMouseMoved(java.awt.event.MouseEvent evt) {                                       
  595. // TODO add your handling code here:
  596.     if (!bigMapLabel.isEnteredSign(evt.getX(), evt.getY())) {
  597.         setCursor(Cursor.getDefaultCursor());
  598.     } else {
  599.         setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
  600.     }
  601. }                                      
  602.     // Variables declaration - do not modify                     
  603.     private javax.swing.JButton addButton;
  604.     private javax.swing.JPanel adjustMapPanel;
  605.     private javax.swing.JButton advancedButton;
  606.     private static com.mwq.map.mwing.BigMapLabel bigMapLabel;
  607.     private javax.swing.JMenuItem createMenuItem;
  608.     private javax.swing.JMenuItem deleteMenuItem;
  609.     private javax.swing.JButton downButton;
  610.     private javax.swing.JTextField keywordTextField;
  611.     private javax.swing.JButton leftButton;
  612.     private javax.swing.JPanel leftPanel;
  613.     private javax.swing.JPanel managePanel;
  614.     private javax.swing.JButton manageSortButton;
  615.     private javax.swing.JButton revertButton;
  616.     private javax.swing.JButton rightButton;
  617.     private javax.swing.JPanel rightPanel;
  618.     private javax.swing.JPanel searchButtonPanel;
  619.     private javax.swing.JPanel searchConditionPanel;
  620.     private javax.swing.JPanel searchPanel;
  621.     private javax.swing.JList searchResultList;
  622.     private javax.swing.JScrollPane searchResultScrollPane;
  623.     private javax.swing.JSeparator separator;
  624.     private javax.swing.JButton setMapButton;
  625.     private javax.swing.JMenuItem showMenuItem;
  626.     private javax.swing.JPopupMenu signPopupMenu;
  627.     private javax.swing.JButton simpleButton;
  628.     private javax.swing.JSlider slider;
  629.     private com.mwq.map.mwing.SmallMapLabel smallMapLabel;
  630.     private javax.swing.JButton subButton;
  631.     private javax.swing.JButton upButton;
  632.     private javax.swing.JMenuItem updateMenuItem;
  633.     // End of variables declaration                   
  634.     public static com.mwq.map.mwing.BigMapLabel getBigMapLabel() {
  635.         return bigMapLabel;
  636.     }
  637. }