zsh_root
2024-01-02 046905340273e5996ba0d4fce2df52b236d960e3
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
package Frame;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import javax.swing.Box;
import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.event.InternalFrameEvent;
import javax.swing.event.InternalFrameListener;
 
import ColorAndFont.buttonTitle;
import PbuliClass.JButtonModel;
import PbuliClass.ShowMessage;
import PbuliClass.Systems;
import PbuliClass.jinternalFrame;
 
/**²é¿´ÊµÊ±±¨ÎÄ*/
public class LookUdpTxt extends jinternalFrame  {
    
    /** 
     * 
     */
    private static final long serialVersionUID = 1L;
    
    JButtonModel start=null;//¿ªÊ¼°´Å¥
    JButtonModel stop=null;//Í£Ö¹°´Å¥
    JButtonModel save=null;//±£´æ°´Å¥
    JButtonModel clear=null;//Çå¿Õ±¨ÎÄ
    JButtonModel justDisplay=null;//Ö»¿´Î»Öñ¨ÎÄ
    JButtonModel justWaring=null;//Ö»¿´¸æ¾¯±¨ÎÄ
    JButtonModel lookAll=null;//²é¿´È«²¿±¨ÎÄ
    static JTextArea textArea=null;
    JPanel mb1=null;
    JScrollPane scrollPane=null;
    String message=null;
    static boolean st=false;
    static boolean just_look_display=false;
    static boolean just_look_warning=false;
    static boolean look_all=true;
    
 
    public LookUdpTxt() {
        String title="ʵʱ±¨ÎÄÐÅÏ¢²é¿´";
        if(Systems.sys().getLanguage().equals("English")) {
            title="Real-time message information view";
        }
        this.setTitle(title);
        this.addInternalFrameListener(new InternalFrameListener() {
            public void internalFrameOpened(InternalFrameEvent e) {                
            }
            
            public void internalFrameIconified(InternalFrameEvent e) {
                
            }
            
            public void internalFrameDeiconified(InternalFrameEvent e) {
                
            }
            
            public void internalFrameDeactivated(InternalFrameEvent e) {                
            }
            
            public void internalFrameClosing(InternalFrameEvent e) {
            }
            
            public void internalFrameClosed(InternalFrameEvent e) {    
                st=false;
                textArea=null;
            }
            
            public void internalFrameActivated(InternalFrameEvent e) {
                
            }
        });
        Container rq=getContentPane();//»ñÈ¡ÈÝÆ÷
        rq.setLayout(new BorderLayout());
        rq.setBackground(Color.white);
        rq.add(getMb1(),BorderLayout.NORTH);
        rq.add(getGd(),BorderLayout.CENTER);
        this.setFrameIcon(new ImageIcon("image/icon/udpicon.png"));//ÉèÖô°Ìåͼ±ê
 
    }
    
    public static JTextArea getAreaTxt() {
        if(textArea==null) {
            textArea=new JTextArea(10,10);//Îı¾Óò¶ÔÏó
            
        }
        return textArea;
    }
    
    public static boolean getSt() {
        return st;
    }
    
    public static boolean getJust_look_display() {
        return just_look_display;
    }
    
    public static boolean getJust_look_warning() {
        return just_look_warning;
    }
    
    public static boolean getLook_all() {
        return look_all;
    }
    
    public JPanel getMb1() {
        if(mb1==null) {
            mb1=new JPanel();
            mb1.setBackground(Color.white);
            Box topicBox = Box.createHorizontalBox();// ´´½¨Ò»¸öˮƽÏäÈÝÆ÷
            topicBox.add(getStart());//Ìí¼ÓËÑË÷Îı¾¿ò
            topicBox.add(Box.createHorizontalStrut(15));// Ìí¼ÓÒ»¸ö3ÏñËØ¿íµÄˮƽ֧Öù
            topicBox.add(getStop());//Ìí¼ÓËÑË÷°´Å¥
            topicBox.add(Box.createHorizontalStrut(15));// Ìí¼ÓÒ»¸ö3ÏñËØ¿íµÄˮƽ֧Öù
            topicBox.add(getClear());
            topicBox.add(Box.createHorizontalStrut(15));// Ìí¼ÓÒ»¸ö3ÏñËØ¿íµÄˮƽ֧Öù
            topicBox.add(getJustDisplay());//
            topicBox.add(Box.createHorizontalStrut(15));// Ìí¼ÓÒ»¸ö3ÏñËØ¿íµÄˮƽ֧Öù
            topicBox.add(getJustWaring());//
            topicBox.add(Box.createHorizontalStrut(15));// Ìí¼ÓÒ»¸ö3ÏñËØ¿íµÄˮƽ֧Öù
            topicBox.add(getJustDisplay());//
            topicBox.add(Box.createHorizontalStrut(15));// Ìí¼ÓÒ»¸ö3ÏñËØ¿íµÄˮƽ֧Öù
            topicBox.add(getLookAll());//
            topicBox.add(Box.createHorizontalStrut(15));// Ìí¼ÓÒ»¸ö3ÏñËØ¿íµÄˮƽ֧Öù
            topicBox.add(getSave());//Ìí¼ÓËÑË÷°´Å¥
            mb1.add(topicBox);
            
        }
        return mb1;
    }
    
    /**»ñÈ¡¹ö¶¯Ãæ°å*/
    public JScrollPane getGd() {
        if(scrollPane==null) {
            scrollPane=new JScrollPane(getAreaTxt());
        }
        return scrollPane;
    }
    
    
    
    /**»ñÈ¡¿ªÊ¼°´Å¥*/
    public JButtonModel getStart() {
        if(start==null) {
            start=new JButtonModel("¿ªÊ¼");
            start.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    textArea.setText("    ÒÑÆô¶¯¼àÌý£¡\n");
                    st=true;
                }
            });
            
        }
        return start;
    }
    
    /**»ñÈ¡ÔÝÍ£°´Å¥*/
    public JButtonModel getStop() {
        if(stop==null) {
            stop=new JButtonModel("ÔÝÍ£");
            stop.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    st=false;
                }
            });
            
        }
        return stop;
    }
    
    /**»ñÈ¡ÔÝÍ£°´Å¥*/
    public JButtonModel getSave() {
        if(save==null) {
            save=new JButtonModel(buttonTitle.getSave());            
            save.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    st=false;
                    JFileChooser chooser = new JFileChooser(
                            "./savefile/");// °Ñ¡°./backup/¡±×÷Ϊ·¾¶´´½¨ÎļþÑ¡ÔñÆ÷
                    int option=chooser.showSaveDialog(getMb1());    //Èç¹ûÈ·¶¨Ôò·µ»Ø0£¬È¡Ïû»ò¹Ø±Õ·µ»Ø1                                
                    String path=chooser.getSelectedFile()+".txt";//Îļþ±£´æÂ·¾¶
                    File file=new File(path);
                    //Èç¹ûÑ¡ÔñµÄÊÇÈ·¶¨Ö´ÐÐÈçϱ£´æ²Ù×÷
                    if(option==JFileChooser.APPROVE_OPTION) {//Ñ¡ÔñÈ·ÈÏ£¨yes¡¢ok£©ºó·µ»Ø¸ÃÖµ                                        
 
                        try {
                            file.createNewFile(); 
                            FileWriter out=new FileWriter(file);//ÎļþÊä³ö×Ö·ûÁ÷
                            out.write(textArea.getText());
                            out.close();
                            ShowMessage.saveSuccess();
                            st=true;
                        } catch (IOException e1) {                        
                            e1.printStackTrace();
                        }    
                    }
                    
                }
            });
            
        }
        return save;
    }
    
    
    /**Çå¿Õ±¨Îİ´Å¥*/
    public JButtonModel getClear() {
        if(clear==null){
            clear=new JButtonModel("Çå¿Õ");
            clear.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    textArea.setText("");
                    
                }
            });
        }
        return clear;
        
    }
    
    /**Ö»¿´Î»Öñ¨ÎÄÊý¾Ý*/
    public JButtonModel getJustDisplay() {
        if(justDisplay==null) {
            justDisplay=new JButtonModel("λÖñ¨ÎÄ");
            justDisplay.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    textArea.setText("");
                    just_look_warning=false;    
                    look_all=false;
                    just_look_display=true;
                }
            });
        }
        return justDisplay;
    }
    
    /**Ö»¿´¸æ¾¯±¨ÎÄÊý¾Ý*/
    public JButtonModel getJustWaring() {
        if(justWaring==null) {
            justWaring=new JButtonModel("¸æ¾¯±¨ÎÄ");
            justWaring.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    textArea.setText("");
                    look_all=false;
                    just_look_display=false;
                    just_look_warning=true;
                }
            });        
            
        }
        return justWaring;
    }
    
    /**²é¿´È«²¿±¨ÎÄÊý¾Ý*/
    public JButtonModel getLookAll() {
        if(lookAll==null) {
            lookAll=new JButtonModel("È«²¿±¨ÎÄ");
            lookAll.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    textArea.setText("");
                    just_look_warning=false;
                    just_look_display=false;
                    look_all=true;    
                }
            });            
        }
        return lookAll;
    }
 
}