zsh_root
2024-01-02 7b595546af704983dbafcd0d385c8768ddacefc2
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
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.JCheckBoxModel;
import PbuliClass.JlableModel;
import PbuliClass.ShowMessage;
import PbuliClass.Systems;
import PbuliClass.jinternalFrame;
 
/**²é¿´ÊµÊ±±¨ÎÄ*/
public class ModBusManage extends jinternalFrame  {
 
    /** 
     * 
     */
    private static final long serialVersionUID = 1L;
    
    static JTextArea textArea=null;
    JButtonModel start=null;//¿ªÊ¼°´Å¥
    JButtonModel stop=null;//Í£Ö¹°´Å¥
    JButtonModel save=null;//±£´æ°´Å¥
    JButtonModel clear=null;//Çå¿Õ±¨ÎÄ
    
    
    
    JCheckBoxModel mod_start=null;
    JlableModel mod_port=new JlableModel("¼àÌý¶Ë¿Ú:");
    JlableModel mod_adress=new JlableModel("ÆðʼµØÖ·:");
    JlableModel mod_lenth=new JlableModel("Êý¾Ý³¤¶È:");
    JlableModel mod_id=new JlableModel("µ¥ÔªID:");
    
    JPanel mb1=null;
    JPanel mb2=null;
    JScrollPane scrollPane=null;
    String message=null;
    static boolean star=false;
    static boolean ceshi=true;
 
 
    public ModBusManage() {    
        String title="ÆøÌå¼ì²â±¨ÎÄ";
        if(Systems.sys().getLanguage().equals("English")) {
            title="Gas detection message";
        }
        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) {    
                star=false;
                ceshi=true;
                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);
//        rq.add(getMb2(),BorderLayout.SOUTH);            
        this.setFrameIcon(new ImageIcon("image/icon/TCP.png"));//ÉèÖô°Ìåͼ±ê
 
    }
 
  public static JTextArea get_text_area() {
      if(textArea==null) {
          textArea=new JTextArea(10,10);
      }
    return textArea;
  }
    
  public static boolean getStar() {
        return star;
    }
 
  public static boolean get_ceshi() {
      return ceshi;
  }
 
    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(getSave());
            mb1.add(topicBox);
 
        }
        return mb1;
    }
 
 
    public JPanel getMb2() {
        if(mb2==null) {
            mb2=new JPanel();
            mb2.setBackground(Color.white);
            Box topicBox = Box.createHorizontalBox();// ´´½¨Ò»¸öˮƽÏäÈÝÆ÷
            topicBox.add(mod_port);
            topicBox.add(Box.createHorizontalStrut(15));// Ìí¼ÓÒ»¸ö3ÏñËØ¿íµÄˮƽ֧Öù
            topicBox.add(mod_adress);
            topicBox.add(Box.createHorizontalStrut(15));// Ìí¼ÓÒ»¸ö3ÏñËØ¿íµÄˮƽ֧Öù
            topicBox.add(mod_lenth);
            topicBox.add(Box.createHorizontalStrut(15));// Ìí¼ÓÒ»¸ö3ÏñËØ¿íµÄˮƽ֧Öù
            topicBox.add(mod_id);
            mb2.add(topicBox);
 
        }
        return mb2;
    }
 
    /**»ñÈ¡¹ö¶¯Ãæ°å*/
    public JScrollPane getGd() {
        if(scrollPane==null) {
            scrollPane=new JScrollPane(get_text_area());
        }
        return scrollPane;
    }
 
 
    /**»ñÈ¡¿ªÊ¼°´Å¥*/
    public JButtonModel getStart() {
        if(start==null) {
            start=new JButtonModel("¿ªÊ¼");
            start.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    textArea.setText("Æô¶¯¼àÌý£¡\n");
                    star=true;
                    
                }
            });
 
        }
        return start;
    }
 
    /**»ñÈ¡ÔÝÍ£°´Å¥*/
    public JButtonModel getStop() {
        if(stop==null) {
            stop=new JButtonModel("ÔÝÍ£");
            stop.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    star=false;
                    textArea.setText("ÒÑÔÝÍ£¼àÌý£¡\n");
                }
            });
 
        }
        return stop;
    }
 
    /**»ñÈ¡±£´æ°´Å¥*/
    public JButtonModel getSave() {
        if(save==null) {
            save=new JButtonModel(buttonTitle.getSave());            
            save.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    star=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();
                        } 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;
    }
 
    
}