ManageSignDialog.java
资源名称:MapModule.rar [点击查看]
上传用户:njlgjx
上传日期:2022-08-07
资源大小:9105k
文件大小:14k
源码类别:
图形图象
开发平台:
Java
- /*
- * CreateSignDialog.java
- *
- * Created on 2008年7月1日, 下午4:00
- */
- package com.mwq.map.frame;
- import com.mwq.map.*;
- import com.mwq.map.dao.Dao;
- import com.mwq.map.mwing.BigMapLabel;
- import com.mwq.map.tool.InstancePool;
- import com.mwq.map.tool.MapProcessor;
- import com.mwq.map.tool.ScreenSize;
- import java.util.Vector;
- import javax.swing.JOptionPane;
- import javax.swing.SwingUtilities;
- /**
- *
- * @author Administrator
- */
- public class ManageSignDialog extends javax.swing.JDialog {
- private Dao dao = Dao.getInstance();
- private MapProcessor mapProcessor = InstancePool.getMapProcessor();
- /** Creates new form CreateSignDialog */
- public ManageSignDialog(java.awt.Frame parent, boolean modal, String title) {
- super(parent, modal);
- initComponents();
- if (title.equals("修改标记")) {
- setTitle("修改标记");// 设置对话框名称
- Vector sign = dao.selectClickSignV(mapProcessor.getRightClickToMapX(),
- mapProcessor.getRightClickToMapY());// 获得欲修改标记的信息
- titleTextField.setText(sign.get(2).toString());// 填写标记名称
- sortTreePanel.getTextField().setName(sign.get(3).toString());// 保存所属类型的主键
- sortTreePanel.getTextField().setText(sign.get(4).toString());// 填写所属类型
- calendarPanel.getTextField().setText(sign.get(7).toString());// 填写创建日期
- remarkTextArea.setText(sign.get(8).toString());// 填写标记说明
- if ((Integer) sign.get(5) == 0) {// 不显示标记文本
- noRadioButton.setSelected(true);
- }
- }
- ScreenSize.centered(this);
- }
- /** This method is called from within the constructor to
- * initialize the form.
- * WARNING: Do NOT modify this code. The content of this method is
- * always regenerated by the Form Editor.
- */
- @SuppressWarnings("unchecked")
- // <editor-fold defaultstate="collapsed" desc="Generated Code">
- private void initComponents() {
- showButtonGroup = new javax.swing.ButtonGroup();
- titleLabel = new javax.swing.JLabel();
- titleTextField = new javax.swing.JTextField();
- sortLabel = new javax.swing.JLabel();
- sortTreePanel = new com.mwq.map.mwing.MTreePanel();
- dateLabel = new javax.swing.JLabel();
- calendarPanel = new com.mwq.map.calendar.CalendarPanel();
- remarkLabel = new javax.swing.JLabel();
- remarkScrollPane = new javax.swing.JScrollPane();
- remarkTextArea = new javax.swing.JTextArea();
- showLabel = new javax.swing.JLabel();
- yesRadioButton = new javax.swing.JRadioButton();
- noRadioButton = new javax.swing.JRadioButton();
- submitButton = new javax.swing.JButton();
- exitButton = new javax.swing.JButton();
- setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- setTitle("创建标记");
- titleLabel.setText("标记名称:");
- titleTextField.setColumns(12);
- titleTextField.addKeyListener(new java.awt.event.KeyAdapter() {
- public void keyTyped(java.awt.event.KeyEvent evt) {
- titleTextFieldKeyTyped(evt);
- }
- });
- sortLabel.setText("所属类型:");
- dateLabel.setText("创建日期:");
- remarkLabel.setText("标记说明:");
- remarkTextArea.setColumns(20);
- remarkTextArea.setRows(5);
- remarkScrollPane.setViewportView(remarkTextArea);
- showLabel.setText("<html>默认情况下为显示标记名称,如果不希望显示标记名称,可以<br>选中下面的否单选按钮:</html>");
- showButtonGroup.add(yesRadioButton);
- yesRadioButton.setSelected(true);
- yesRadioButton.setText("是");
- showButtonGroup.add(noRadioButton);
- noRadioButton.setText("否");
- submitButton.setText("确定");
- submitButton.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- submitButtonActionPerformed(evt);
- }
- });
- exitButton.setText("退出");
- exitButton.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- exitButtonActionPerformed(evt);
- }
- });
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addContainerGap()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
- .addComponent(showLabel)
- .addGroup(layout.createSequentialGroup()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(titleLabel)
- .addComponent(sortLabel)
- .addComponent(dateLabel)
- .addComponent(remarkLabel))
- .addGap(4, 4, 4)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGap(2, 2, 2)
- .addComponent(yesRadioButton)
- .addGap(34, 34, 34)
- .addComponent(noRadioButton))
- .addGroup(layout.createSequentialGroup()
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(titleTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(calendarPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
- .addGroup(layout.createSequentialGroup()
- .addComponent(submitButton)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(exitButton))
- .addComponent(remarkScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 283, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addComponent(sortTreePanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))))
- .addContainerGap())
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addContainerGap()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(titleLabel)
- .addComponent(titleTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
- .addComponent(sortLabel)
- .addComponent(sortTreePanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
- .addComponent(dateLabel)
- .addComponent(calendarPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(remarkLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(remarkScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(showLabel)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(yesRadioButton)
- .addComponent(noRadioButton))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(exitButton)
- .addComponent(submitButton))
- .addContainerGap())
- );
- pack();
- }// </editor-fold>
- private void exitButtonActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- this.dispose();
- }
- private void submitButtonActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- String title = titleTextField.getText().trim();// 获得标记名称
- String sortId = sortTreePanel.getTextField().getName();// 获得所属类型的主键
- String date = calendarPanel.getTextField().getText();// 获得创建日期
- if (title.length() == 0) {// 标记名称为空
- JOptionPane.showMessageDialog(null, "标记名称不允许为空!", "友情提示",
- JOptionPane.INFORMATION_MESSAGE, null);
- titleTextField.requestFocus();// 请求获得焦点
- return;
- }
- if (sortId == null) {// 所属类型为空
- JOptionPane.showMessageDialog(null, "所属类型不允许为空!", "友情提示",
- JOptionPane.INFORMATION_MESSAGE, null);
- sortTreePanel.getTextField().requestFocus();// 请求获得焦点
- return;
- }
- if (date.length() == 0) {// 创建日期为空
- JOptionPane.showMessageDialog(null, "创建日期不允许为空!", "友情提示",
- JOptionPane.INFORMATION_MESSAGE, null);
- calendarPanel.getTextField().requestFocus();// 请求获得焦点
- return;
- }
- String remark = remarkTextArea.getText().trim();// 获得标记说明
- int show = 1;// 默认为显示标记文本
- if (noRadioButton.isSelected()) {
- show = 0;// 不显示标记文本
- }
- int x = mapProcessor.getRightClickX();// 在地图显示区中的水平坐标
- int y = mapProcessor.getRightClickY();// 在地图显示区中的垂直坐标
- int mapX = mapProcessor.getRightClickToMapX();// 在地图中的水平坐标
- int mapY = mapProcessor.getRightClickToMapY();// 在地图中的垂直坐标
- if (getTitle().equals("创建标记")) {// 创建标记
- int id = dao.insertSign(sortId, mapX, mapY, title, show,
- mapProcessor.getScale(), date, remark);// 保存到数据库
- BigMapLabel.addSign(id, x, y, title, (show == 1 ? true : false));// 添加标记
- SwingUtilities.updateComponentTreeUI(MapPanel.getBigMapLabel());// 刷新地图显示区
- } else {// 修改标记
- BigMapLabel.updateSign(x, y, title, (show == 1 ? true : false));// 修改标记信息
- SwingUtilities.updateComponentTreeUI(MapPanel.getBigMapLabel());// 刷新地图显示区
- dao.updateSign(mapX, mapY, title, sortId, show, date, remark);// 保存到数据库
- }
- this.dispose();
- }
- private void titleTextFieldKeyTyped(java.awt.event.KeyEvent evt) {
- // TODO add your handling code here:
- if (titleTextField.getText().length() >= 10) {
- evt.consume();
- }
- }
- /**
- * @param args the command line arguments
- */
- public static void main(String args[]) {
- java.awt.EventQueue.invokeLater(new Runnable() {
- public void run() {
- ManageSignDialog dialog = new ManageSignDialog(new javax.swing.JFrame(), true, "");
- dialog.addWindowListener(new java.awt.event.WindowAdapter() {
- @Override
- public void windowClosing(java.awt.event.WindowEvent e) {
- System.exit(0);
- }
- });
- dialog.setVisible(true);
- }
- });
- }
- // Variables declaration - do not modify
- private com.mwq.map.calendar.CalendarPanel calendarPanel;
- private javax.swing.JLabel dateLabel;
- private javax.swing.JButton exitButton;
- private javax.swing.JRadioButton noRadioButton;
- private javax.swing.JLabel remarkLabel;
- private javax.swing.JScrollPane remarkScrollPane;
- private javax.swing.JTextArea remarkTextArea;
- private javax.swing.ButtonGroup showButtonGroup;
- private javax.swing.JLabel showLabel;
- private javax.swing.JLabel sortLabel;
- private com.mwq.map.mwing.MTreePanel sortTreePanel;
- private javax.swing.JButton submitButton;
- private javax.swing.JLabel titleLabel;
- private javax.swing.JTextField titleTextField;
- private javax.swing.JRadioButton yesRadioButton;
- // End of variables declaration
- }