📄 dialogenterzhuanghao.java
字号:
package net.aetherial.gis.cutAndLink.zhuanghao;
import java.awt.*;
import javax.swing.*;
import com.borland.jbcl.layout.XYLayout;
import com.borland.jbcl.layout.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import org.w3c.dom.Node;
import net.aetherial.gis.cutAndLink.CLFrame;
import net.aetherial.gis.cutAndLink.DynamicPanel;
import java.awt.event.KeyEvent;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2004</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class DialogEnterZhuanghao
extends JDialog {
JPanel panel1 = new JPanel();
XYLayout xYLayout1 = new XYLayout();
JButton jButton1 = new JButton();
JButton jButton2 = new JButton();
JTextField jTextField1 = new JTextField();
JTextField jTextField2 = new JTextField();
JLabel jLabel1 = new JLabel();
JLabel jLabel2 = new JLabel();
private Node currentTrack = null;
DynamicPanel dp = null;
CLFrame clf = null;
public DialogEnterZhuanghao(Frame owner, String title, boolean modal) {
super(owner, title, modal);
try {
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
jbInit();
pack();
}
catch (Exception exception) {
exception.printStackTrace();
}
}
public DialogEnterZhuanghao(CLFrame owner, Node currentTrack, DynamicPanel dp) {
this(owner, "添加桩号", false);
clf = owner;
this.setInitData(currentTrack, dp);
}
public void setInitData(Node currentTrack, DynamicPanel dp) {
this.currentTrack = currentTrack;
this.dp = dp;
}
private void jbInit() throws Exception {
panel1.setLayout(xYLayout1);
jButton1.setText(" 确 定 ");
jButton1.addActionListener(new DialogEnterZhuanghao_jButton_actionAdapter(this));
jButton2.setText(" 取 消 ");
jButton2.addActionListener(new DialogEnterZhuanghao_jButton_actionAdapter(this));
jLabel1.setText("输入桩号名称:");
jLabel2.setText("输入桩号数值:");
getContentPane().add(panel1);
panel1.add(jLabel1, new XYConstraints(56, 47, -1, -1));
panel1.add(jLabel2, new XYConstraints(56, 83, -1, -1));
panel1.add(jButton2, new XYConstraints(183, 122, -1, -1));
panel1.add(jButton1, new XYConstraints(88, 122, -1, -1));
panel1.add(jTextField1, new XYConstraints(147, 44, 126, -1));
panel1.add(jTextField2, new XYConstraints(147, 80, 126, 22));
this.setButtonEnterKey(this.jButton1);
this.setJTextEnterKey(this.jTextField2,new DialogEnterZhuanghao_jButton_actionAdapter(this));
}
private void setButtonEnterKey(JButton button) {
button.registerKeyboardAction(button.getActionForKeyStroke(KeyStroke
.getKeyStroke(KeyEvent.VK_SPACE, 0, true)),
KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, true),
JComponent.WHEN_FOCUSED);
}
private void setJTextEnterKey(JTextField textField,
ActionListener actionListener) {
textField.registerKeyboardAction(actionListener,
KeyStroke.getKeyStroke(KeyEvent.VK_ENTER,
0, true),
JComponent.WHEN_FOCUSED);
}
public void show() {
this.setSize(350, 212);
Dimension screenDim = Toolkit.getDefaultToolkit().getScreenSize();
this.setLocation(
(screenDim.width - 350) / 2,
(screenDim.height - 212) / 2
);
super.show();
}
private String getZhuanghaoString(double data, String name) {
String n = "";
int zhengshu = (int) data;
int xiaoshu = (int) ( (data - zhengshu) * 1000);
if ( (xiaoshu < 100) && (xiaoshu >= 10)) {
n = "K" + zhengshu + "+0" + xiaoshu;
}
else if (xiaoshu < 10) {
n = "K" + zhengshu + "+00" + xiaoshu;
}
else {
n = "K" + zhengshu + "+" + xiaoshu;
}
if (name.trim().equals("")) {
return n;
}
else {
return n + "(" + name + ")";
}
}
public void jButton_actionPerformed(ActionEvent e) {
if (e.getSource().equals(this.jButton2)) {
System.out.println("h:" + this.getHeight() + ",w:" + this.getWidth());
this.dispose();
this.hide();
}
else {
Zhuanghao zh = new Zhuanghao();
CreateZhuanghao create = null;
Exception flag = null;
double enterData = 0.0;
try {
enterData = Double.parseDouble(this.jTextField2.getText().trim());
zh.setData(enterData);
zh.setZhuanghaoName(getZhuanghaoString(enterData,
this.jTextField1.getText().trim()));
}
catch (NumberFormatException ex) {
flag = ex;
JOptionPane.showMessageDialog(this, "桩号数值不是数字。", "插入错误",
JOptionPane.ERROR_MESSAGE);
return;
}
try {
create = new CreateZhuanghao(zh, this.currentTrack);
}
catch (Exception ex1) {
flag = ex1;
JOptionPane.showMessageDialog(this, ex1.getMessage(), "插入错误",
JOptionPane.ERROR_MESSAGE);
return;
}
if (flag == null) {
if (create.getZhuanghaoWaypoint() != null) {
clf.jPanelCut.init();
clf.jPanelCut.setSelectedWaypointTo(create.getZhuanghaoWaypoint());
clf.frameMemoryShow();
}
this.dp.repaint();
this.dispose();
this.hide();
}
}
}
}
class DialogEnterZhuanghao_jButton_actionAdapter
implements ActionListener {
private DialogEnterZhuanghao adaptee;
DialogEnterZhuanghao_jButton_actionAdapter(DialogEnterZhuanghao adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton_actionPerformed(e);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -