wenzheng.yang
2023-06-19 f66c10e6a1837a6704f2296d1a7c740a53e88fb4
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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
package frame;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.util.Vector;
import javax.swing.ImageIcon;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.table.DefaultTableModel;
 
import data_model.Dell_lixian;
import data_model.Dell_shebei;
import data_model.Dell_system;
import data_model.Jilu;
import data_model.tb_shebei;
import publicclass.GetNowTime;
import publicclass.JButtonModel;
import publicclass.JButtonModel2;
import publicclass.JlableModel;
import publicclass.Savelog;
import publicclass.ShowMessage;
import publicclass.greateTables;
public class Index1 extends JFrame implements WindowListener{
 
    /**
     * 
     */
    private static final long serialVersionUID = 1L;
 
    JPanel mb;//Ãæ°å
    static JTextArea are=null;
    static String chooseip="1";
    static String chooseport="";
    static boolean openlog=false;
    static boolean startjx=false;//¿ªÊ¼Êý¾Ý½âÎö
    int jisuan=0;
    JScrollPane gd1;
    JScrollPane gd2;
    JScrollPane gd3;
    JScrollPane gd4;//ÿÈÕ¼à²â½á¹û
    static JTable table=null;//ÉêÃ÷±í¸ñ
    JTable table2=null;//ÉêÃ÷±í¸ñ
    JTable table4=null;//ÉêÃ÷±í¸ñ
    DefaultTableModel tableModel=null;//ÉùÃ÷±í¸ñÄ£ÐÍ    
    DefaultTableModel tableModel2=null;//ÉùÃ÷±í¸ñÄ£ÐÍ
    DefaultTableModel tableModel4=null;//ÉùÃ÷±í¸ñÄ£ÐÍ
    Vector<Vector<String>> rowData=null;
    Vector<Vector<String>> rowData2=null;
    Vector<Vector<String>> rowData4=null;
    static boolean showare=false;
    JButtonModel but_start=null;//Ñ¡ÔñbinÎļþ
    JButtonModel but_clear=null;//Ñ¡ÔñbinÎļþ
    JButtonModel but_shuaxin1=null;//ˢбí¸ñ
    JButtonModel search=null;//ËÑË÷°´Å¥
    static JButtonModel2 tcpnum;
    static JButtonModel2 udpnum;
    JButtonModel2 jbt_chushi_enhd=null;//³õʼ»¯Æ«ÒÆÁ¿³õʼֵ
    JButtonModel2 jbt_send=null;//·¢ËÍÉèÖûù×¼Õ¾×ó±ß
    JButtonModel2 jbt_getbase_jwd=null;//»ñÈ¡»ù×¼Öµ¾­Î³¶È
    JTextField searchFileld=null;//ËÑË÷Îı¾¿ò
    JTextField send_Fileld=null;//ËÑË÷Îı¾¿ò
    JlableModel  jl_UDP=new JlableModel("UDP¼àÌý¶Ë¿Ú:"+Dell_system.getPort());
    //JlableModel  jl_tcp=new JlableModel("TCP¶Ë¿Ú:"+tcpport);
    static int num=0;
    JComboBox<String> datatype=null;//Êý¾ÝÀàÐÍ
    JComboBox<String> baseanchor=null;//Ñ¡Ôñ»ù×¼Õ¾ID
    static String datatypeis="È«²¿Êý¾ÝÀàÐÍ";
    static boolean chushi_enhd=false;
    static boolean start_jiexi=false;
    static String tagid="0";
 
    public Index1() {//¹¹Ôì·½·¨
        Toolkit toolkit = getToolkit();// »ñµÃ´°Ì幤¾ß°ü
        Dimension screenSize = toolkit.getScreenSize();// »ñÈ¡ÆÁÄ»´óС
        int width =1500;// ¼ÆËã´°Ìåпí¶È
        int height =700;// ¼ÆËã´°Ìåпí¶È
        int w=(int) (screenSize.width* 0.15);
        int h=(int) (screenSize.height * 0.15);
        this.setBounds(w,h, width, height);//ÉèÖô°Ìå³ß´ç
        this.setTitle("ÀëÏ߼ǼÈí¼þV1.01");
        Container rq=getContentPane();//»ñÈ¡ÈÝÆ÷
        rq.setLayout(new BorderLayout());
        rq.setBackground(Color.white);
        rq.add(getMb(),BorderLayout.CENTER);
        this.setVisible(true);//ʹ´°Ìå¿É¼û
        this.addWindowListener((WindowListener) this);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//ÉèÖô°Ì幨±Õ·½Ê½
        Image image=new ImageIcon("./image/icon/jiance.png").getImage();
        this.setIconImage(image); 
        Savelog.save_in_txt("Èí¼þ´ò¿ª");
 
    }
 
    public JPanel getMb() {
        if(mb==null) {
            mb=new JPanel();
            mb.setLayout(null);
            mb.setBackground(Color.white);
            int x=5;
            int y=6;
            int y2=x+40;
            mb.add(jl_UDP);
            //    mb.add(jl_tcp);
            mb.add(getGd1());
            mb.add(getGd2());
            mb.add(getGd3());
            mb.add(getBut_start());
            mb.add(getBut_clear());    
            mb.add(getSearchFileld());
            mb.add(getSearch());
            //mb.add(getTcpnum());
            mb.add(getUdpnum());    
            mb.add(getBut_shuaxin1());
            jl_UDP.setBounds(x+3, y,140,30);
            //jl_tcp.setBounds(x+140, y,120,30);
            //getTcpnum().setBounds(x+140+120+10, y,100,30);
            getUdpnum().setBounds(x+150, y,250,30);
            int h1=500;
            getGd1().setBounds(x, y2,500,500);
 
 
            getSearchFileld().setBounds(x+530, y,150,30);
            getSearch().setBounds(x+530+155, y,80,30);
            getBut_shuaxin1().setBounds(x+530+155+100, y,80,30);
//            getJbt_chushi_enhd().setBounds(x+530+155+200, y,150,30);
//            getBut_jisuan().setBounds(x+530+155+370, y,100,30);
//            getBut_openlog().setBounds(x+530+155+490, y,120,30);
//            getBut_more().setBounds(x+530+155+490+140, y,80,30);
 
            getGd2().setBounds(x+530, y2,840,300);
            getGd3().setBounds(x+530, y2+330,840,200);
//            getGd4().setBounds(x, y2+650,1370,300);
 
//            getBaseanchor().setBounds(x+530, y2+540,200,30);
//            getSend_Fileld().setBounds(x+740, y2+540,350,30);
//            getJbt_getbase_jwd().setBounds(x+1100,y2+540,180,30);
//            getJbt_send().setBounds(x+1290,y2+540,80,30);
 
            getBut_start().setBounds(x, y2+h1+20,100,40);
            getBut_clear().setBounds(x+120, y2+h1+20,100,40);
 
 
 
        }
        return mb;
    }
 
    public void setMb(JPanel mb) {
        this.mb = mb;
    }
 
    public static JTextArea getAre() {
        if(are==null) {
            are=new JTextArea(10,10);
            are.setBackground(Color.WHITE);
            are.setForeground(Color.blue);
        }
        return are;
    }
 
    public JScrollPane getGd2() {
        if(gd2==null) {
            gd2=new JScrollPane(getTable());
            gd2.setBackground(Color.white);
            gd2.setForeground(Color.white);
        }
        return gd2;
    }
 
 
 
    @Override
    public void windowActivated(WindowEvent e) {
        // TODO ×Ô¶¯Éú³ÉµÄ·½·¨´æ¸ù
 
    }
 
    @Override
    public void windowClosed(WindowEvent e) {
        // TODO ×Ô¶¯Éú³ÉµÄ·½·¨´æ¸ù
 
    }
 
    @Override
    public void windowClosing(WindowEvent e) {
        Savelog.save_in_txt("Èí¼þ¹Ø±Õ");
        System.exit(0);
 
    }
 
    @Override
    public void windowDeactivated(WindowEvent e) {
        // TODO ×Ô¶¯Éú³ÉµÄ·½·¨´æ¸ù
 
    }
 
    @Override
    public void windowDeiconified(WindowEvent e) {
        // TODO ×Ô¶¯Éú³ÉµÄ·½·¨´æ¸ù
 
    }
 
    @Override
    public void windowIconified(WindowEvent e) {
        // TODO ×Ô¶¯Éú³ÉµÄ·½·¨´æ¸ù
 
    }
 
    @Override
    public void windowOpened(WindowEvent e) {
        // TODO ×Ô¶¯Éú³ÉµÄ·½·¨´æ¸ù
 
    }
 
    
    /**Ìí¼Ó±í¸ñÐÐÏòÁ¿Êý¾Ý·½·¨*/ 
    //"±àºÅ","Ãû³Æ","µØÖ·","״̬","¿¨ºÅ","¸üÐÂʱ¼ä","Ìí¼Óʱ¼ä"
    public void getRowData( Vector<tb_shebei>  tagvc ) {
        int size=tagvc.size();
        for(int i=0;i<size;i++) {
            tb_shebei tag=tagvc.get(i);
            Vector<String> row = new Vector<>();
            row.add(tag.getTagid());
            row.add(tag.getName());
            row.add(tag.getIp());
            String zai=tag.getState();
            if(zai.equals("1")) {
                zai="ÔÚÏß";
            }else {
                zai="ÀëÏß";
            }
            row.add(zai);
            row.add(tag.getIcid());
            row.add(tag.getGengxintime());
            row.add(tag.getAddtime());
            tableModel.addRow(row);
        }        
    }
    
    
    /**Ìí¼Ó±í¸ñÐÐÏòÁ¿Êý¾Ý·½·¨*/ 
    public void getRowData2( Vector<Jilu>  forwards ) {
        int size=forwards.size();
        for(int i=0;i<size;i++) {
            Jilu a2=forwards.get(i);
            Vector<String> row = new Vector<>();
            row.add(a2.getId());
            row.add(a2.getTagid());            
            row.add(a2.getName());
            row.add(a2.getAddtime());
            row.add(a2.getAlltime());
            tableModel2.addRow(row);
        }        
    }
 
 
 
    public JScrollPane getGd1() {
        if(gd1==null) {
            gd1=new JScrollPane(getAre());
        }
        return gd1;
    }
    public JScrollPane getGd3() {
        if(gd3==null) {
            gd3=new JScrollPane(getTable2());
        }
        return gd3;
    }
 
    /**»ñÈ¡»ùÕ¾±í¸ñµÄ·½·¨*/    
    public JTable getTable() {
        if(table==null) {            
            //Ìí¼Ó±í¸ñÁÐÏòÁ¿
            String[] columnNames= {"±àºÅ","Ãû³Æ","µØÖ·","״̬","¿¨ºÅ","¸üÐÂʱ¼ä","Ìí¼Óʱ¼ä"};//±í¸ñÁÐÃû
            Vector<String> columnName=new Vector<>();
            for(int i=0;i<columnNames.length;i++){
                columnName.add(columnNames[i]);            
            }
 
            greateTables tables=new greateTables();
            if(tableModel==null) {
                tableModel=new DefaultTableModel(rowData, columnName){  
                    /**
                     * 
                     */
                    private static final long serialVersionUID = 1L;
 
                    //  ÊµÏÖÈÃÕû¸ö±í¸ñ²»²»ÔÊÐí±»±à¼­
                    public boolean isCellEditable(int row,int column){  
                        return false;  
                    }  
                };
                table=tables.greateTable(tableModel);
                table.setBackground(Color.white);                
                getRowData(Dell_shebei.getTagvc());
            }
 
        }
        return table;
 
    }
 
    public JTable getTable2() {//
        if(table2==null) {
            String[] columnNames= {"ÐòºÅ","ÀëÏß","Ãû³Æ","ÀëÏßÌí¼Óʱ¼ä","ÀëÏßʱ³¤/s"};//±í¸ñÁÐÃû
            //Ìí¼Ó±í¸ñÁÐÏòÁ¿
            Vector<String> columnName=new Vector<>();
            for(int i=0;i<columnNames.length;i++){
                columnName.add(columnNames[i]);            
            }
            greateTables tables=new greateTables();
            tableModel2=new DefaultTableModel(rowData2, columnName){ 
                /**
                 * 
                 */
                private static final long serialVersionUID = 1L;
 
                public boolean isCellEditable(int row,int column){ //  ÊµÏÖÈÃÕû¸ö±í¸ñ²»²»ÔÊÐí±»±à¼­ 
                    return false;  
                }  
            };
 
            table2=tables.greateTable(tableModel2);    
            getRowData2(Dell_lixian.getvec());    
        }
        return table2;
 
    }
 
 
    /**@param String message,
     * @param String ip,
     * @param int datatypeÊý¾ÝÀàÐÍ*/
    public static void baowen_show(String message,String ip,String datatype) {
        if(showare) {
            if(chooseip.equals("1") || ip.equals(chooseip)) {
                if(datatypeis.equals("È«²¿Êý¾ÝÀàÐÍ")) {//
                    are.append(GetNowTime.sss()+":"+message+"\n");
                    are.setCaretPosition(are.getText().length());
                }else if(datatype.equals(datatypeis)) {
                    are.append(message+"\n");
                    are.setCaretPosition(are.getText().length());
                }
            }
        }
    }
 
    public static void ara_show(String message) {
        are.append(GetNowTime.sss()+":"+message+"\n");
        are.setCaretPosition(are.getText().length());
    }
 
    public JButtonModel getBut_start() {
        if(but_start==null) {
            but_start=new JButtonModel("²é¿´±¨ÎÄ");
            but_start.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    if(!showare) {
                        showare=true;
                        but_start.setText("ÔÝÍ£²é¿´");
                    }else {
                        showare=false;
                        but_start.setText("¿ªÊ¼²é¿´");
                    }
 
                }
            });
 
        }
        return but_start;
    }
 
    //
    public JButtonModel getBut_clear() {
        if(but_clear==null) {
            but_clear=new JButtonModel("Çå¿Õ´°¿Ú");
            but_clear.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    are.setText("");
                }
            });
 
        }
        return but_clear;
    }
 
    public void setBut_start(JButtonModel but_start) {
        this.but_start = but_start;
    }
 
    
    public static int getNum() {
        return num;
    }
 
    public static void setNum(int num) {
        Index1.num = num;
    }
 
    
    /**»ñÈ¡ËÑË÷Îı¾¿òµÄ·½·¨*/
    public JTextField getSearchFileld() {
        if(searchFileld==null){
            searchFileld=new JTextField(10);
            searchFileld.addKeyListener(new KeyListener() {    //¼üÅÌʼþ¼àÌý                
                public void keyTyped(KeyEvent e) {                
 
                }                    
                public void keyReleased(KeyEvent e) {
                    int keyCode=e.getKeyCode();
                    if(keyCode==KeyEvent.VK_ENTER) {
                        getSearch().doClick();//ËÑË÷°´Å¥±»µã»÷
                    }                        
                }                    
                public void keyPressed(KeyEvent e) {                    
 
                }
            });
 
        }
        return searchFileld;
    }
 
 
    /**»ñÈ¡ËÑË÷°´Å¥µÄ·½·¨*/    
    public JButtonModel getSearch() {
        if(search==null){
            search=new JButtonModel("ËÑË÷");
            search.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    String serch=getSearchFileld().getText().trim();
                    tagid=serch;
                    if(serch.length()>=1) {
                        int size=Dell_shebei.getshebeivc(serch).size();
                        ShowMessage.zidingyi("ËÑË÷µ½Êý¾Ý"+size);
                        updateSerch(serch);    
                    }else {
                        ShowMessage.zidingyi("ÄãËÑË÷µÄÉ豸"+serch+"²»´æÔÚ...");
                    }
                }
            });
 
        }
        return search;
    }
 
    /**ËÑË÷·½·¨*/
    public void updateSerch(String a) {    
        if(Dell_shebei.getshebeivc(a).size()==0) {
            ShowMessage.zidingyi("ÄãËÑË÷µÄÉ豸"+a+"²»´æÔÚ...");
            return;
        }
        int tagnum=table.getRowCount();//±í¸ñ×ÜÐÐÊý
        if(tagnum >0 ) {
            for (int i = 0; i < tagnum; i++) {//ɾ³ýËùÓÐÐÐ
                tableModel.removeRow(0);                            
            }
            //½«ÁбíÖÐËùÓнá¹û¼¯¸øµ½list¼¯ºÏ
            getRowData(Dell_shebei.getshebeivc(a));
        }
 
 
    }
 
    public static JButtonModel2 getTcpnum() {
        if(tcpnum==null) {
            tcpnum=new JButtonModel2("TCP:0");
        }
        return tcpnum;
    }
 
    public static JButtonModel2 getUdpnum() {
        if(udpnum==null) {
            udpnum=new JButtonModel2("UDP:0");
        }
        return udpnum;
    }
 
    public  JButtonModel getBut_shuaxin1() {
        if(but_shuaxin1==null) {
            but_shuaxin1=new JButtonModel("ˢбí¸ñ");
            but_shuaxin1.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    updateTable();
                    tagid="0";
                }
            });
        }
        return but_shuaxin1;
    }
 
    /**ˢбí¸ñ·½·¨*/
    public void updateTable() {    
        if(tableModel !=null) {    
            if(Dell_shebei.getTagvc().size()!=0) {
                tableModel.getDataVector().clear();    
                tableModel2.getDataVector().clear();    
                getRowData(Dell_shebei.getTagvc());
                getRowData2(Dell_lixian.getvec());
                gd2.validate();
                gd3.validate();
            }
            
            ShowMessage.zidingyi("Ë¢ÐÂÍê±Ï");
        }
    }
 
    public static boolean isShoware() {
        return showare;
    }
 
    public static void setShoware(boolean showare) {
        Index1.showare = showare;
    }
 
    public static String getTagid() {
        return tagid;
    }
 
    
    
 
 
}