提交 | 用户 | 时间
|
149dd0
|
1 |
package com.iailab.netsdk.demo.frame.AutoRegister; |
H |
2 |
|
|
3 |
import java.awt.BorderLayout; |
|
4 |
import java.awt.Dimension; |
|
5 |
import java.awt.FlowLayout; |
|
6 |
import java.awt.event.ActionEvent; |
|
7 |
import java.awt.event.ActionListener; |
|
8 |
import java.awt.event.WindowAdapter; |
|
9 |
import java.awt.event.WindowEvent; |
|
10 |
|
|
11 |
import javax.swing.JButton; |
|
12 |
import javax.swing.JDialog; |
|
13 |
import javax.swing.JLabel; |
|
14 |
import javax.swing.JOptionPane; |
|
15 |
import javax.swing.JPanel; |
|
16 |
import javax.swing.JPasswordField; |
|
17 |
import javax.swing.JTextField; |
|
18 |
|
|
19 |
import com.iailab.netsdk.common.BorderEx; |
|
20 |
import com.iailab.netsdk.common.DeviceManagerListener; |
|
21 |
import com.iailab.netsdk.common.Res; |
|
22 |
|
|
23 |
/** |
|
24 |
* 在树上添加设备 |
|
25 |
*/ |
|
26 |
public class AddDeviceDialog extends JDialog{ |
|
27 |
private static final long serialVersionUID = 1L; |
|
28 |
|
|
29 |
private DeviceManagerListener listener; |
|
30 |
public void addDeviceManagerListener(DeviceManagerListener listener) { |
|
31 |
this.listener = listener; |
|
32 |
} |
|
33 |
|
|
34 |
public AddDeviceDialog(){ |
|
35 |
setTitle(Res.string().getAddDevice()); |
|
36 |
setLayout(new BorderLayout()); |
|
37 |
setModal(true); |
|
38 |
pack(); |
|
39 |
setSize(220, 180); |
|
40 |
setResizable(false); |
|
41 |
setLocationRelativeTo(null); |
|
42 |
setDefaultCloseOperation(DISPOSE_ON_CLOSE); // 释放窗体 |
|
43 |
|
|
44 |
AddDevicePanel addDevicePanel = new AddDevicePanel(); |
|
45 |
add(addDevicePanel, BorderLayout.CENTER); |
|
46 |
|
|
47 |
addWindowListener(new WindowAdapter() { |
|
48 |
public void windowClosing(WindowEvent e){ |
|
49 |
dispose(); |
|
50 |
} |
|
51 |
}); |
|
52 |
} |
|
53 |
|
|
54 |
/* |
|
55 |
* 添加设备面板 |
|
56 |
*/ |
|
57 |
private class AddDevicePanel extends JPanel { |
|
58 |
private static final long serialVersionUID = 1L; |
|
59 |
|
|
60 |
public AddDevicePanel() { |
|
61 |
BorderEx.set(this, "", 2); |
|
62 |
setLayout(new FlowLayout()); |
|
63 |
|
|
64 |
JLabel deviceIdLabel = new JLabel(Res.string().getDeviceID(), JLabel.CENTER); |
|
65 |
JLabel usernameLabel = new JLabel(Res.string().getUserName(), JLabel.CENTER); |
|
66 |
JLabel passwordLabel = new JLabel(Res.string().getPassword(), JLabel.CENTER); |
|
67 |
|
|
68 |
deviceIdLabel.setPreferredSize(new Dimension(60, 21)); |
|
69 |
usernameLabel.setPreferredSize(new Dimension(60, 21)); |
|
70 |
passwordLabel.setPreferredSize(new Dimension(60, 21)); |
|
71 |
|
|
72 |
deviceIdTextField = new JTextField(); |
|
73 |
usernameTextField = new JTextField(); |
|
74 |
passwordPasswordField = new JPasswordField(); |
|
75 |
|
|
76 |
deviceIdTextField.setPreferredSize(new Dimension(120, 20)); |
|
77 |
usernameTextField.setPreferredSize(new Dimension(120, 20)); |
|
78 |
passwordPasswordField.setPreferredSize(new Dimension(120, 20)); |
|
79 |
|
|
80 |
JButton addDeviceBtn = new JButton(Res.string().getAdd()); |
|
81 |
JButton cancelBtn = new JButton(Res.string().getCancel()); |
|
82 |
|
|
83 |
addDeviceBtn.setPreferredSize(new Dimension(90, 21)); |
|
84 |
cancelBtn.setPreferredSize(new Dimension(90, 21)); |
|
85 |
|
|
86 |
add(deviceIdLabel); |
|
87 |
add(deviceIdTextField); |
|
88 |
add(usernameLabel); |
|
89 |
add(usernameTextField); |
|
90 |
add(passwordLabel); |
|
91 |
add(passwordPasswordField); |
|
92 |
add(addDeviceBtn); |
|
93 |
add(cancelBtn); |
|
94 |
|
|
95 |
// 添加 |
|
96 |
addDeviceBtn.addActionListener(new ActionListener() { |
|
97 |
@Override |
|
98 |
public void actionPerformed(ActionEvent arg0) { |
|
99 |
if(deviceIdTextField.getText().equals("")) { |
|
100 |
JOptionPane.showMessageDialog(null, Res.string().getInput() + Res.string().getDeviceID(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); |
|
101 |
return; |
|
102 |
} |
|
103 |
|
|
104 |
if(usernameTextField.getText().equals("")) { |
|
105 |
JOptionPane.showMessageDialog(null, Res.string().getInput() + Res.string().getUserName(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); |
|
106 |
return; |
|
107 |
} |
|
108 |
|
|
109 |
if((new String(passwordPasswordField.getPassword()).trim()).equals("")) { |
|
110 |
JOptionPane.showMessageDialog(null, Res.string().getInput() + Res.string().getPassword(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); |
|
111 |
return; |
|
112 |
} |
|
113 |
|
|
114 |
dispose(); |
|
115 |
listener.onDeviceManager(deviceIdTextField.getText(), |
|
116 |
usernameTextField.getText(), |
|
117 |
new String(passwordPasswordField.getPassword()).trim()); |
|
118 |
} |
|
119 |
}); |
|
120 |
|
|
121 |
// 取消,关闭 |
|
122 |
cancelBtn.addActionListener(new ActionListener() { |
|
123 |
@Override |
|
124 |
public void actionPerformed(ActionEvent arg0) { |
|
125 |
dispose(); |
|
126 |
} |
|
127 |
}); |
|
128 |
} |
|
129 |
} |
|
130 |
|
|
131 |
private JTextField deviceIdTextField; |
|
132 |
private JTextField usernameTextField; |
|
133 |
private JPasswordField passwordPasswordField; |
|
134 |
} |