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

图形图象

开发平台:

Java

  1. /*
  2.  * CreateSignDialog.java
  3.  *
  4.  * Created on 2008年7月1日, 下午4:00
  5.  */
  6. package com.mwq.map.frame;
  7. import com.mwq.map.*;
  8. import com.mwq.map.dao.Dao;
  9. import com.mwq.map.mwing.BigMapLabel;
  10. import com.mwq.map.tool.InstancePool;
  11. import com.mwq.map.tool.MapProcessor;
  12. import com.mwq.map.tool.ScreenSize;
  13. import java.util.Vector;
  14. import javax.swing.JOptionPane;
  15. import javax.swing.SwingUtilities;
  16. /**
  17.  *
  18.  * @author  Administrator
  19.  */
  20. public class ManageSignDialog extends javax.swing.JDialog {
  21.     private Dao dao = Dao.getInstance();
  22.     private MapProcessor mapProcessor = InstancePool.getMapProcessor();
  23.     /** Creates new form CreateSignDialog */
  24.     public ManageSignDialog(java.awt.Frame parent, boolean modal, String title) {
  25.         super(parent, modal);
  26.         initComponents();
  27.         if (title.equals("修改标记")) {
  28.             setTitle("修改标记");// 设置对话框名称
  29.             Vector sign = dao.selectClickSignV(mapProcessor.getRightClickToMapX(),
  30.                     mapProcessor.getRightClickToMapY());// 获得欲修改标记的信息
  31.             titleTextField.setText(sign.get(2).toString());// 填写标记名称
  32.             sortTreePanel.getTextField().setName(sign.get(3).toString());// 保存所属类型的主键
  33.             sortTreePanel.getTextField().setText(sign.get(4).toString());// 填写所属类型
  34.             calendarPanel.getTextField().setText(sign.get(7).toString());// 填写创建日期
  35.             remarkTextArea.setText(sign.get(8).toString());// 填写标记说明
  36.             if ((Integer) sign.get(5) == 0) {// 不显示标记文本
  37.                 noRadioButton.setSelected(true);
  38.             }
  39.         }
  40.         ScreenSize.centered(this);
  41.     }
  42.     /** This method is called from within the constructor to
  43.      * initialize the form.
  44.      * WARNING: Do NOT modify this code. The content of this method is
  45.      * always regenerated by the Form Editor.
  46.      */
  47.     @SuppressWarnings("unchecked")
  48.     // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
  49.     private void initComponents() {
  50.         showButtonGroup = new javax.swing.ButtonGroup();
  51.         titleLabel = new javax.swing.JLabel();
  52.         titleTextField = new javax.swing.JTextField();
  53.         sortLabel = new javax.swing.JLabel();
  54.         sortTreePanel = new com.mwq.map.mwing.MTreePanel();
  55.         dateLabel = new javax.swing.JLabel();
  56.         calendarPanel = new com.mwq.map.calendar.CalendarPanel();
  57.         remarkLabel = new javax.swing.JLabel();
  58.         remarkScrollPane = new javax.swing.JScrollPane();
  59.         remarkTextArea = new javax.swing.JTextArea();
  60.         showLabel = new javax.swing.JLabel();
  61.         yesRadioButton = new javax.swing.JRadioButton();
  62.         noRadioButton = new javax.swing.JRadioButton();
  63.         submitButton = new javax.swing.JButton();
  64.         exitButton = new javax.swing.JButton();
  65.         setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
  66.         setTitle("创建标记");
  67.         titleLabel.setText("标记名称:");
  68.         titleTextField.setColumns(12);
  69.         titleTextField.addKeyListener(new java.awt.event.KeyAdapter() {
  70.             public void keyTyped(java.awt.event.KeyEvent evt) {
  71.                 titleTextFieldKeyTyped(evt);
  72.             }
  73.         });
  74.         sortLabel.setText("所属类型:");
  75.         dateLabel.setText("创建日期:");
  76.         remarkLabel.setText("标记说明:");
  77.         remarkTextArea.setColumns(20);
  78.         remarkTextArea.setRows(5);
  79.         remarkScrollPane.setViewportView(remarkTextArea);
  80.         showLabel.setText("<html>默认情况下为显示标记名称,如果不希望显示标记名称,可以<br>选中下面的否单选按钮:</html>");
  81.         showButtonGroup.add(yesRadioButton);
  82.         yesRadioButton.setSelected(true);
  83.         yesRadioButton.setText("是");
  84.         showButtonGroup.add(noRadioButton);
  85.         noRadioButton.setText("否");
  86.         submitButton.setText("确定");
  87.         submitButton.addActionListener(new java.awt.event.ActionListener() {
  88.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  89.                 submitButtonActionPerformed(evt);
  90.             }
  91.         });
  92.         exitButton.setText("退出");
  93.         exitButton.addActionListener(new java.awt.event.ActionListener() {
  94.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  95.                 exitButtonActionPerformed(evt);
  96.             }
  97.         });
  98.         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  99.         getContentPane().setLayout(layout);
  100.         layout.setHorizontalGroup(
  101.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  102.             .addGroup(layout.createSequentialGroup()
  103.                 .addContainerGap()
  104.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
  105.                     .addComponent(showLabel)
  106.                     .addGroup(layout.createSequentialGroup()
  107.                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  108.                             .addComponent(titleLabel)
  109.                             .addComponent(sortLabel)
  110.                             .addComponent(dateLabel)
  111.                             .addComponent(remarkLabel))
  112.                         .addGap(4, 4, 4)
  113.                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  114.                             .addGroup(layout.createSequentialGroup()
  115.                                 .addGap(2, 2, 2)
  116.                                 .addComponent(yesRadioButton)
  117.                                 .addGap(34, 34, 34)
  118.                                 .addComponent(noRadioButton))
  119.                             .addGroup(layout.createSequentialGroup()
  120.                                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  121.                                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  122.                                     .addComponent(titleTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  123.                                     .addComponent(calendarPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  124.                                     .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
  125.                                         .addGroup(layout.createSequentialGroup()
  126.                                             .addComponent(submitButton)
  127.                                             .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  128.                                             .addComponent(exitButton))
  129.                                         .addComponent(remarkScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 283, javax.swing.GroupLayout.PREFERRED_SIZE))
  130.                                     .addComponent(sortTreePanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))))
  131.                 .addContainerGap())
  132.         );
  133.         layout.setVerticalGroup(
  134.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  135.             .addGroup(layout.createSequentialGroup()
  136.                 .addContainerGap()
  137.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  138.                     .addComponent(titleLabel)
  139.                     .addComponent(titleTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  140.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  141.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
  142.                     .addComponent(sortLabel)
  143.                     .addComponent(sortTreePanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  144.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  145.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
  146.                     .addComponent(dateLabel)
  147.                     .addComponent(calendarPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  148.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  149.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  150.                     .addComponent(remarkLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
  151.                     .addComponent(remarkScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE))
  152.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  153.                 .addComponent(showLabel)
  154.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  155.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  156.                     .addComponent(yesRadioButton)
  157.                     .addComponent(noRadioButton))
  158.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  159.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  160.                     .addComponent(exitButton)
  161.                     .addComponent(submitButton))
  162.                 .addContainerGap())
  163.         );
  164.         pack();
  165.     }// </editor-fold>                        
  166. private void exitButtonActionPerformed(java.awt.event.ActionEvent evt) {                                           
  167. // TODO add your handling code here:
  168.     this.dispose();
  169. }                                          
  170. private void submitButtonActionPerformed(java.awt.event.ActionEvent evt) {                                             
  171. // TODO add your handling code here:    
  172.     String title = titleTextField.getText().trim();// 获得标记名称
  173.     String sortId = sortTreePanel.getTextField().getName();// 获得所属类型的主键
  174.     String date = calendarPanel.getTextField().getText();// 获得创建日期
  175.     if (title.length() == 0) {// 标记名称为空
  176.         JOptionPane.showMessageDialog(null, "标记名称不允许为空!", "友情提示",
  177.                 JOptionPane.INFORMATION_MESSAGE, null);
  178.         titleTextField.requestFocus();// 请求获得焦点
  179.         return;
  180.     }
  181.     if (sortId == null) {// 所属类型为空
  182.         JOptionPane.showMessageDialog(null, "所属类型不允许为空!", "友情提示",
  183.                 JOptionPane.INFORMATION_MESSAGE, null);
  184.         sortTreePanel.getTextField().requestFocus();// 请求获得焦点
  185.         return;
  186.     }
  187.     if (date.length() == 0) {// 创建日期为空
  188.         JOptionPane.showMessageDialog(null, "创建日期不允许为空!", "友情提示",
  189.                 JOptionPane.INFORMATION_MESSAGE, null);
  190.         calendarPanel.getTextField().requestFocus();// 请求获得焦点
  191.         return;
  192.     }
  193.     String remark = remarkTextArea.getText().trim();// 获得标记说明
  194.     int show = 1;// 默认为显示标记文本
  195.     if (noRadioButton.isSelected()) {
  196.         show = 0;// 不显示标记文本
  197.     }
  198.     int x = mapProcessor.getRightClickX();// 在地图显示区中的水平坐标
  199.     int y = mapProcessor.getRightClickY();// 在地图显示区中的垂直坐标
  200.     int mapX = mapProcessor.getRightClickToMapX();// 在地图中的水平坐标
  201.     int mapY = mapProcessor.getRightClickToMapY();// 在地图中的垂直坐标
  202.     if (getTitle().equals("创建标记")) {// 创建标记
  203.         int id = dao.insertSign(sortId, mapX, mapY, title, show,
  204.                 mapProcessor.getScale(), date, remark);// 保存到数据库
  205.         BigMapLabel.addSign(id, x, y, title, (show == 1 ? true : false));// 添加标记
  206.         SwingUtilities.updateComponentTreeUI(MapPanel.getBigMapLabel());// 刷新地图显示区
  207.     } else {// 修改标记
  208.         BigMapLabel.updateSign(x, y, title, (show == 1 ? true : false));// 修改标记信息
  209.         SwingUtilities.updateComponentTreeUI(MapPanel.getBigMapLabel());// 刷新地图显示区
  210.         dao.updateSign(mapX, mapY, title, sortId, show, date, remark);// 保存到数据库
  211.     }
  212.     this.dispose();
  213. }                                            
  214. private void titleTextFieldKeyTyped(java.awt.event.KeyEvent evt) {                                        
  215. // TODO add your handling code here:
  216.     if (titleTextField.getText().length() >= 10) {
  217.         evt.consume();
  218.     }
  219. }                                       
  220.     /**
  221.      * @param args the command line arguments
  222.      */
  223.     public static void main(String args[]) {
  224.         java.awt.EventQueue.invokeLater(new Runnable() {
  225.             public void run() {
  226.                 ManageSignDialog dialog = new ManageSignDialog(new javax.swing.JFrame(), true, "");
  227.                 dialog.addWindowListener(new java.awt.event.WindowAdapter() {
  228.                     @Override
  229.                     public void windowClosing(java.awt.event.WindowEvent e) {
  230.                         System.exit(0);
  231.                     }
  232.                 });
  233.                 dialog.setVisible(true);
  234.             }
  235.         });
  236.     }
  237.     // Variables declaration - do not modify                     
  238.     private com.mwq.map.calendar.CalendarPanel calendarPanel;
  239.     private javax.swing.JLabel dateLabel;
  240.     private javax.swing.JButton exitButton;
  241.     private javax.swing.JRadioButton noRadioButton;
  242.     private javax.swing.JLabel remarkLabel;
  243.     private javax.swing.JScrollPane remarkScrollPane;
  244.     private javax.swing.JTextArea remarkTextArea;
  245.     private javax.swing.ButtonGroup showButtonGroup;
  246.     private javax.swing.JLabel showLabel;
  247.     private javax.swing.JLabel sortLabel;
  248.     private com.mwq.map.mwing.MTreePanel sortTreePanel;
  249.     private javax.swing.JButton submitButton;
  250.     private javax.swing.JLabel titleLabel;
  251.     private javax.swing.JTextField titleTextField;
  252.     private javax.swing.JRadioButton yesRadioButton;
  253.     // End of variables declaration                   
  254. }