潘志宝
5 天以前 f853b02cb7b265379eceb2f0e3c38f9d63bb1b21
提交 | 用户 | 时间
149dd0 1 package com.iailab.netsdk.demo.frame.ThermalCamera;
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.KeyEvent;
9 import java.awt.event.KeyListener;
10
11 import javax.swing.DefaultComboBoxModel;
12 import javax.swing.JButton;
13 import javax.swing.JComboBox;
14 import javax.swing.JDialog;
15 import javax.swing.JLabel;
16 import javax.swing.JOptionPane;
17 import javax.swing.JPanel;
18 import javax.swing.JSplitPane;
19 import javax.swing.JTextField;
20
21 import com.iailab.netsdk.common.BorderEx;
22 import com.iailab.netsdk.common.Res;
23 import com.iailab.netsdk.demo.module.ThermalCameraModule;
24 import com.iailab.netsdk.lib.ToolKits;
25 import com.iailab.netsdk.lib.NetSDKLib.NET_RADIOMETRYINFO;
26
27
28 /**
29  * 查询测温项对话框
30  */
31 public class ItemQueryDialog extends JDialog{
32
33     /**
34      * 
35      */
36     private static final long serialVersionUID = 1L;
37     
38     public ItemQueryDialog() {
39         setTitle(Res.string().getShowInfo("ITEM_TEMPER"));
40         setLayout(new BorderLayout());
41         setModal(true);
42         pack();
43         setSize(365, 460);
44         setResizable(false);
45         setLocationRelativeTo(null);
46         setDefaultCloseOperation(DISPOSE_ON_CLOSE);
47         
48         ///////////////////////////////
49         queryPanel = new QueryPanel();
50         showPanel = new QueryShowPanel();
51         
52         add(queryPanel, BorderLayout.NORTH);
53         add(showPanel, BorderLayout.CENTER);
54
55     }
56     
57     
58     /**
59      * 查询测温项界面
60      * */
61     public class QueryPanel extends JPanel {
62         /**
63          * 
64          */
65         private static final long serialVersionUID = 1L;
66         
67         public QueryPanel() {
68             BorderEx.set(this, Res.string().getShowInfo("QUERY_CONDITION"), 1);
69             setLayout(new BorderLayout());            
70
71             JLabel presetIdLabel = new JLabel(Res.string().getShowInfo("PRESET_ID"), JLabel.CENTER);
72             presetIdTextField = new JTextField("1");
73             JLabel ruleIdLabel = new JLabel(Res.string().getShowInfo("RULE_ID"), JLabel.CENTER);
74             ruleIdTextField = new JTextField("1");
75             JLabel meterTypeLabel = new JLabel(Res.string().getShowInfo("METER_TYPE"), JLabel.CENTER);
76             meterTypeComboBox = new JComboBox();
77             meterTypeComboBox.setModel(new DefaultComboBoxModel(Res.string().getMeterTypeList()));
78             queryBtn = new JButton(Res.string().getShowInfo("QUERY"));
79             
80             Dimension lableDimension = new Dimension(85, 20);
81             Dimension textFieldDimension = new Dimension(80, 20);
82             Dimension btnDimension = new Dimension(100, 20);
83
84             presetIdLabel.setPreferredSize(lableDimension);
85             presetIdTextField.setPreferredSize(textFieldDimension);
86             ruleIdLabel.setPreferredSize(lableDimension);
87             ruleIdTextField.setPreferredSize(textFieldDimension);
88             meterTypeLabel.setPreferredSize(lableDimension);
89             meterTypeComboBox.setPreferredSize(textFieldDimension);
90             JLabel label = new JLabel();
91             label.setPreferredSize(new Dimension(40, 20));
92             queryBtn.setPreferredSize(btnDimension);
93             
94             JPanel topPanel = new JPanel();
95             topPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 1, 10));            
96             topPanel.add(presetIdLabel);
97             topPanel.add(presetIdTextField);
98             topPanel.add(ruleIdLabel);
99             topPanel.add(ruleIdTextField);
100             
101             JPanel bottomPanel = new JPanel();
102             bottomPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 1, 10));            
103             bottomPanel.add(meterTypeLabel);
104             bottomPanel.add(meterTypeComboBox);
105             bottomPanel.add(label);
106             bottomPanel.add(queryBtn);
107             
108             JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
109             splitPane.setDividerSize(0);
110             splitPane.setBorder(null);
111             splitPane.add(topPanel, JSplitPane.TOP);
112             splitPane.add(bottomPanel, JSplitPane.BOTTOM);
113             
114             add(splitPane, BorderLayout.CENTER);
115             
116             listener = new NumberKeyListener();
117             
118             presetIdTextField.addKeyListener(listener);
119             ruleIdTextField.addKeyListener(listener);
120             
121             queryBtn.addActionListener(new ActionListener() {
122
123                 @Override
124                 public void actionPerformed(ActionEvent e) {
125                     queryItemInfo();
126                 }
127             });
128         }
129         
130         public void queryItemInfo() {
131             try {
132                 showPanel.clearData();
133                 
134                 int nPresetId = Integer.parseInt(presetIdTextField.getText());
135                 int nRuleId = Integer.parseInt(ruleIdTextField.getText());
136                 int nMeterType = meterTypeComboBox.getSelectedIndex() + 1;
137     
138                 NET_RADIOMETRYINFO stItemInfo = 
139                         ThermalCameraModule.queryItemTemper(ThermalCameraFrame.THERMAL_CHANNEL, nPresetId, nRuleId, nMeterType);
140                 if (stItemInfo == null) {
141                     JOptionPane.showMessageDialog(null, ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE);
142                     return;
143                 }
144                 
145                 showPanel.updateData(stItemInfo);
146                 
147             }catch(NumberFormatException e) {
148                 JOptionPane.showMessageDialog(null, Res.string().getShowInfo("INPUT_ILLEGAL"), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE);
149             }
150         }
151         
152         private NumberKeyListener listener;
153         
154         private JTextField presetIdTextField;
155         private JTextField ruleIdTextField;
156         private JComboBox meterTypeComboBox;
157         private JButton queryBtn;
158     }
159     
160     /**
161      * 查询显示界面
162      * */
163     public class QueryShowPanel extends JPanel {
164         /**
165          * 
166          */
167         private static final long serialVersionUID = 1L;
168
169         public QueryShowPanel() {
170             BorderEx.set(this, Res.string().getShowInfo("QUERY_RESULT"), 1);
171             setLayout(new FlowLayout(FlowLayout.CENTER, 5, 25));
172             
173             JLabel meterTypeLabel = new JLabel(Res.string().getShowInfo("METER_TYPE"), JLabel.LEFT);
174             meterTypeTextField = new JTextField();
175             JLabel temperUnitLabel = new JLabel(Res.string().getShowInfo("TEMPER_UNIT"), JLabel.LEFT);
176             temperUnitTextField = new JTextField();
177             JLabel temperAverLabel = new JLabel(Res.string().getShowInfo("TEMPER_AVER"), JLabel.LEFT);
178             temperAverTextField = new JTextField();
179             JLabel temperMaxLabel = new JLabel(Res.string().getShowInfo("TEMPER_MAX"), JLabel.LEFT);
180             temperMaxTextField = new JTextField();
181             JLabel temperMinLabel = new JLabel(Res.string().getShowInfo("TEMPER_MIN"), JLabel.LEFT);
182             temperMinTextField = new JTextField();
183             JLabel temperMidLabel = new JLabel(Res.string().getShowInfo("TEMPER_MID"), JLabel.LEFT);
184             temperMidTextField = new JTextField();
185             JLabel temperStdLabel = new JLabel(Res.string().getShowInfo("TEMPER_STD"), JLabel.LEFT);
186             temperStdTextField = new JTextField();
187             
188             Dimension lableDimension = new Dimension(120, 20);
189             Dimension textFieldDimension = new Dimension(130, 20);
190             meterTypeLabel.setPreferredSize(lableDimension);
191             temperUnitLabel.setPreferredSize(lableDimension);
192             temperAverLabel.setPreferredSize(lableDimension);
193             temperMaxLabel.setPreferredSize(lableDimension);
194             temperMinLabel.setPreferredSize(lableDimension);
195             temperMidLabel.setPreferredSize(lableDimension);
196             temperStdLabel.setPreferredSize(lableDimension);
197             meterTypeTextField.setPreferredSize(textFieldDimension);
198             temperUnitTextField.setPreferredSize(textFieldDimension);
199             temperAverTextField.setPreferredSize(textFieldDimension);
200             temperMaxTextField.setPreferredSize(textFieldDimension);
201             temperMinTextField.setPreferredSize(textFieldDimension);
202             temperMidTextField.setPreferredSize(textFieldDimension);
203             temperStdTextField.setPreferredSize(textFieldDimension);
204             
205             meterTypeTextField.setEditable(false);
206             temperUnitTextField.setEditable(false);
207             temperAverTextField.setEditable(false);
208             temperMaxTextField.setEditable(false);
209             temperMinTextField.setEditable(false);
210             temperMidTextField.setEditable(false);
211             temperStdTextField.setEditable(false);
212
213             add(meterTypeLabel);
214             add(meterTypeTextField);
215             add(temperUnitLabel);
216             add(temperUnitTextField);
217             add(temperMaxLabel);
218             add(temperMaxTextField);
219             add(temperMinLabel);
220             add(temperMinTextField);
221             add(temperMidLabel);
222             add(temperMidTextField);
223             add(temperStdLabel);
224             add(temperStdTextField);
225         }
226         
227         public void updateData(NET_RADIOMETRYINFO stItemInfo) {
228             String[] data = new String[7];
229
230             String [] arrMeterType = Res.string().getMeterTypeList();
231             if (stItemInfo.nMeterType >= 1 && 
232                     stItemInfo.nMeterType <= arrMeterType.length) {
233                 data[0] = arrMeterType[stItemInfo.nMeterType-1];
234             }else {
235                 data[0] = Res.string().getShowInfo("UNKNOWN");
236             }
237             
238             String [] arrTemperUnit = Res.string().getTemperUnitList();
239             if (stItemInfo.nTemperUnit >= 1 && 
240                     stItemInfo.nTemperUnit <= arrTemperUnit.length) {
241                 data[1] = arrTemperUnit[stItemInfo.nTemperUnit-1];
242             }else {
243                 data[1] = Res.string().getShowInfo("UNKNOWN");
244             }
245             
246             data[2] = String.valueOf(stItemInfo.fTemperAver);
247             data[3] = String.valueOf(stItemInfo.fTemperMax);
248             data[4] = String.valueOf(stItemInfo.fTemperMin);
249             data[5] = String.valueOf(stItemInfo.fTemperMid);
250             data[6] = String.valueOf(stItemInfo.fTemperStd);
251             
252             setData(data);
253         }
254         
255         public void clearData() {
256             setData(new String[7]);
257         }
258         
259         private void setData(String[] data) {
260             
261             if (data.length != 7) {
262                 System.err.printf("data length  %d != 7", data.length);
263                 return;
264             }
265
266             meterTypeTextField.setText(data[0]);
267             temperUnitTextField.setText(data[1]);
268             temperAverTextField.setText(data[2]);
269             temperMaxTextField.setText(data[3]);
270             temperMinTextField.setText(data[4]);
271             temperMidTextField.setText(data[5]);
272             temperStdTextField.setText(data[6]);
273         }
274                 
275         private JTextField meterTypeTextField;
276         private JTextField temperUnitTextField;
277         private JTextField temperAverTextField;
278         private JTextField temperMaxTextField;
279         private JTextField temperMinTextField;
280         private JTextField temperMidTextField;
281         private JTextField temperStdTextField;
282     }
283     
284     class NumberKeyListener implements KeyListener {
285         
286         public void keyTyped(KeyEvent e) {
287               int key = e.getKeyChar();
288               if (key < 48 || key > 57) {
289                   e.consume();
290               }
291         }
292
293         public void keyPressed(KeyEvent e) {}
294         
295         public void keyReleased(KeyEvent e) {}
296     }
297     
298     
299     private QueryPanel queryPanel;
300     private QueryShowPanel showPanel;
301 }