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