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 java.io.PrintWriter;
|
import javax.swing.Box;
|
import javax.swing.ComboBoxModel;
|
import javax.swing.DefaultComboBoxModel;
|
import javax.swing.ImageIcon;
|
import javax.swing.JComboBox;
|
import javax.swing.JFileChooser;
|
import javax.swing.JScrollPane;
|
import javax.swing.JTextArea;
|
import javax.swing.JTextField;
|
import javax.swing.event.InternalFrameEvent;
|
import javax.swing.event.InternalFrameListener;
|
import BaoWen.DebugStarMessage;
|
import BaoWen.Udp_Receive;
|
import ColorAndFont.ChooseFont;
|
import ColorAndFont.NothJPanel;
|
import ColorAndFont.UIColor;
|
import ColorAndFont.buttonTitle;
|
import Method.GetNowTime;
|
import PbuliClass.JButtonModel;
|
import PbuliClass.JCheckBoxModel;
|
import PbuliClass.ShowMessage;
|
import PbuliClass.Systems;
|
import PbuliClass.jinternalFrame;
|
import tag.Tag_Dell;
|
import tbDataModel_Dell.Tools;
|
|
/**²é¿´ÊµÊ±±¨ÎÄ*/
|
public class TcpIpManage extends jinternalFrame {
|
|
/**
|
*
|
*/
|
private static final long serialVersionUID = 1L;
|
|
static JTextArea textArea=null;
|
JButtonModel start=null;//¿ªÊ¼°´Å¥
|
JButtonModel save=null;//±£´æ°´Å¥
|
JButtonModel clear=null;//Çå¿Õ±¨ÎÄ
|
JButtonModel jtb_datafrom=null;//²»ÏÔʾÊý¾ÝÀ´Ô´
|
JTextField port=null;//½ÓÊÕ¶Ë¿Ú
|
JTextField ipAdress=null;//½ÓÊÕµØÖ·
|
JTextField sendFile=null;//·¢ËÍÎı¾¿ò
|
JButtonModel sendButton=null;//·¢ËͰ´Å¥
|
JButtonModel jbt_urt=null;//ÔÝÍ£urt½ÓÊÕ
|
NothJPanel mb1=null;
|
NothJPanel mb2=null;
|
JScrollPane scrollPane=null;
|
JComboBox<String> box=null;
|
JComboBox<String> tagbox=null;//±êÇ©¼¯ºÏ
|
JComboBox<String> datatype=null;//Êý¾ÝÀàÐÍ
|
static String xieyi_type="2";//ÐÒéÀàÐÍÑ¡Ôñ
|
String message=null;
|
static String datatypeis="±¨ÎÄÊý¾Ý";
|
static boolean star=false;
|
static String need_guo_lv_tag="Ñ¡Ôñ±êÇ©";
|
JCheckBoxModel openbaowen=null;//¿ªÆô»òÕ߹رձ£´æ±¨Îĸ´Ñ¡¿ò
|
JCheckBoxModel hexsend=null;//HEX·¢ËÍ¿ò
|
JCheckBoxModel hexins=null;//HEX·¢ËÍ¿ò
|
static boolean asclljx=false;//20230709yang
|
boolean starandstop=false;
|
static boolean hexin=false;//ÊÕµ½µÄÊý¾ÝhexÏÔʾ
|
static boolean urt=true;
|
static boolean showfrom=true;//ÊÇ·ñÏÔʾÊý¾ÝÀ´Ô´
|
|
/**Éè¼Æ×ÖÌåÏÔʾЧ¹û Font mf = new Font(String ×ÖÌ壬int ·ç¸ñ£¬int ×ÖºÅ);
|
×ÖÌ壺TimesRoman, Courier, ArialµÈ
|
·ç¸ñ£ºÈý¸ö³£Á¿ Font.PLAIN, Font.BOLD, Font.ITALIC
|
×ֺţº×ֵĴóС£¨°õÊý£©*/
|
public TcpIpManage() {
|
String title="±¨ÎÄÊý¾Ý";
|
if(Systems.sys().getLanguage().equals("English")) {
|
title="Message data";
|
}
|
this.setTitle(title);
|
Container rq=getContentPane();//»ñÈ¡ÈÝÆ÷
|
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;
|
textArea=null;
|
urt=true;
|
need_guo_lv_tag="Ñ¡Ôñ±êÇ©";
|
showfrom=false;
|
asclljx=false;
|
}
|
|
public void internalFrameActivated(InternalFrameEvent e) {
|
|
}
|
});
|
rq.setLayout(new BorderLayout());
|
rq.setBackground(UIColor.getNorth_color());
|
rq.add(getMb1(),BorderLayout.NORTH);
|
rq.add(getGd(),BorderLayout.CENTER);
|
rq.add(getMb2(),BorderLayout.SOUTH);
|
this.setBounds(175, 0, 1000,500);
|
this.setFrameIcon(new ImageIcon("image/icon/TCP.png"));//ÉèÖô°Ìåͼ±ê
|
|
}
|
|
public static String get_xieyi_type() {
|
return xieyi_type;
|
}
|
|
public static JTextArea get_text_area() {
|
if(textArea==null) {
|
textArea=new JTextArea(10,10);
|
textArea.setForeground(UIColor.getTable_font());
|
textArea.setFont(ChooseFont.getFont(13));
|
}
|
return textArea;
|
}
|
|
public static boolean getStar() {
|
return star;
|
}
|
|
|
|
|
public NothJPanel getMb1() {
|
if(mb1==null) {
|
mb1=new NothJPanel();
|
Box topicBox = Box.createHorizontalBox();// ´´½¨Ò»¸öˮƽÏäÈÝÆ÷
|
topicBox.add(Box.createHorizontalStrut(10));// Ìí¼ÓÒ»¸ö3ÏñËØ¿íµÄˮƽ֧Öù
|
topicBox.add(getDatatype());
|
topicBox.add(Box.createHorizontalStrut(15));// Ìí¼ÓÒ»¸ö3ÏñËØ¿íµÄˮƽ֧Öù
|
topicBox.add(getBox());
|
topicBox.add(Box.createHorizontalStrut(20));
|
topicBox.add(getTagbox()) ;
|
topicBox.add(Box.createHorizontalStrut(20));
|
topicBox.add(getStart());//Ìí¼ÓËÑË÷Îı¾¿ò
|
topicBox.add(Box.createHorizontalStrut(15));// Ìí¼ÓÒ»¸ö3ÏñËØ¿íµÄˮƽ֧Öù
|
topicBox.add(getSave());//Ìí¼ÓËÑË÷°´Å¥
|
topicBox.add(Box.createHorizontalStrut(15));
|
topicBox.add(getClear());
|
mb1.add(topicBox);
|
|
}
|
return mb1;
|
}
|
|
public JTextField get_sendFile() {
|
if(sendFile==null) {
|
sendFile=new JTextField(20);
|
}
|
return sendFile;
|
}
|
|
public NothJPanel getMb2() {
|
if(mb2==null) {
|
mb2=new NothJPanel();
|
// JlableModel portext=new JlableModel("¶Ë¿Ú:");
|
// JlableModel ipadresstext=new JlableModel("UDP·¢Ë͵ØÖ·:");
|
Box topicBox = Box.createHorizontalBox();// ´´½¨Ò»¸öˮƽÏäÈÝÆ÷
|
// topicBox.add(ipadresstext);
|
// topicBox.add(Box.createHorizontalStrut(2));// Ìí¼ÓÒ»¸ö3ÏñËØ¿íµÄˮƽ֧Öù
|
// topicBox.add(get_ipadress());
|
// topicBox.add(Box.createHorizontalStrut(2));// Ìí¼ÓÒ»¸ö3ÏñËØ¿íµÄˮƽ֧Öù
|
// topicBox.add(portext);
|
// topicBox.add(Box.createHorizontalStrut(2));// Ìí¼ÓÒ»¸ö3ÏñËØ¿íµÄˮƽ֧Öù
|
// topicBox.add(get_port());
|
// topicBox.add(Box.createHorizontalStrut(15));// Ìí¼ÓÒ»¸ö3ÏñËØ¿íµÄˮƽ֧Öù
|
// topicBox.add(get_sendFile());
|
// topicBox.add(Box.createHorizontalStrut(15));// Ìí¼ÓÒ»¸ö3ÏñËØ¿íµÄˮƽ֧Öù
|
// topicBox.add(get_sendButton());//Ìí¼ÓËÑË÷°´Å¥);
|
|
topicBox.add(Box.createHorizontalStrut(15));
|
topicBox.add(getOpenbaowen());
|
topicBox.add(Box.createHorizontalStrut(15));
|
topicBox.add(getHexins());
|
topicBox.add(Box.createHorizontalStrut(15));
|
topicBox.add(getHexsend());
|
topicBox.add(Box.createHorizontalStrut(15));
|
topicBox.add(getJbt_urt());
|
topicBox.add(Box.createHorizontalStrut(20));
|
topicBox.add(get_jtb_datafrom());
|
mb2.add(topicBox);
|
// mb2.setBackground(Color.gray);//ÐÞ¸ÄÑÕÉ«yang2023.07.08
|
}
|
return mb2;
|
}
|
|
/**»ñÈ¡¹ö¶¯Ãæ°å*/
|
public JScrollPane getGd() {
|
if(scrollPane==null) {
|
scrollPane=new JScrollPane(get_text_area());
|
}
|
return scrollPane;
|
}
|
|
public JTextField get_port() {
|
if(port==null) {
|
port=new JTextField(5);
|
}
|
return port;
|
}
|
|
public JTextField get_ipadress() {
|
if(ipAdress==null) {
|
ipAdress=new JTextField(10);
|
}
|
return ipAdress;
|
}
|
|
public void writeInfo(PrintWriter writer, String text) {
|
writer.println(text);
|
}
|
|
/**»ñÈ¡¿ªÊ¼°´Å¥*/
|
public JButtonModel getStart() {
|
if(start==null) {
|
start=new JButtonModel("¿ª ʼ");
|
start.addActionListener(new ActionListener() {
|
public void actionPerformed(ActionEvent e) {
|
|
if( !starandstop) {
|
starandstop=true;
|
star=true;
|
start.setText(" ÔÝ Í£ ");
|
start.setBackground(Color.red);
|
if(datatypeis.equals("µ÷ÊÔÊý¾Ý")) {
|
textArea.append(DebugStarMessage.getDebug().toString());
|
}
|
String tagid=need_guo_lv_tag;
|
if(need_guo_lv_tag.equals("Ñ¡Ôñ±êÇ©")) {
|
tagid="ËùÓбêÇ©";
|
}
|
textArea.append("µ±Ç°Ñ¡ÔñÊý¾ÝÀàÐÍ:"+datatypeis+",Ñ¡Ôñ²é¿´µÄ±êǩΪ:"+tagid+",¿ªÊ¼²é¿´...\n");
|
}else {
|
starandstop=false;
|
star=false;
|
start.setText(" ¿ª ʼ ");
|
start.setBackground(Color.gray);
|
}
|
|
|
}
|
});
|
|
}
|
return start;
|
}
|
|
public JButtonModel get_jtb_datafrom() {
|
if(jtb_datafrom==null) {
|
jtb_datafrom=new JButtonModel("²»ÏÔʾÊý¾ÝÀ´Ô´");
|
jtb_datafrom.addActionListener(new ActionListener() {
|
public void actionPerformed(ActionEvent e) {
|
if(showfrom) {
|
showfrom=false;
|
jtb_datafrom.setText(" ÏÔʾÊý¾ÝÀ´Ô´ ");
|
}else {
|
showfrom=true;
|
jtb_datafrom.setText(" ²»ÏÔʾÊý¾ÝÀ´Ô´ ");
|
}
|
}
|
});
|
}
|
return jtb_datafrom;
|
}
|
|
/**»ñÈ¡±£´æ°´Å¥*/
|
public JButtonModel getSave() {
|
if(save==null) {
|
save=new JButtonModel(buttonTitle.getSave());
|
save.addActionListener(new ActionListener() {
|
public void actionPerformed(ActionEvent e) {
|
star=false;
|
//ĬÈÏĿ¼
|
String defaultDirectory ="./savefile/";
|
//ĬÈÏÎļþÃû
|
String defaultFilename = GetNowTime.timestamp()+"±¨ÎÄ.txt";
|
|
JFileChooser chooser = new JFileChooser();
|
|
//ÉèÖÃĬÈϱ£´æÂ·¾¶
|
chooser.setCurrentDirectory(new File(defaultDirectory));
|
|
//ÉèÖÃĬÈϱ£´æÎļþÃû
|
chooser.setSelectedFile(new File(defaultFilename));
|
|
int option=chooser.showSaveDialog(getMb1()); //Èç¹ûÈ·¶¨Ôò·µ»Ø0£¬È¡Ïû»ò¹Ø±Õ·µ»Ø1
|
File file=new File(chooser.getSelectedFile().getPath());
|
|
//Èç¹ûÑ¡ÔñµÄÊÇÈ·¶¨Ö´ÐÐÈçϱ£´æ²Ù×÷
|
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 get_sendButton() {
|
if(sendButton==null){
|
sendButton=new JButtonModel("·¢ËÍ");
|
sendButton.addActionListener(new ActionListener() {
|
public void actionPerformed(ActionEvent e) {
|
// TcpClientOneToMany.send(sendFile.getText().trim());
|
String ip=ipAdress.getText().trim();
|
String data=sendFile.getText().trim();
|
String ports=port.getText().trim();
|
|
|
|
if(ip.length()<8 || ports.length()<3 ) {
|
ShowMessage.zidingyi("ÊäÈëµÄµØÖ·»òÕß¶Ë¿ÚÓÐ´í£¡");
|
return;
|
}
|
|
if(asclljx) {
|
data=data.replaceAll(" ","");
|
if(data.length() % 2 !=0) {
|
data=data+"0";
|
}
|
|
byte[] byt=Tools.hexStrToBinaryStr(data);
|
int lenth=byt.length;
|
textArea.append(GetNowTime.now()+"·¢-->: "+Tools.Bytes2HexString(byt)+"\n");
|
Udp_Receive.udp_serch(byt, lenth, ip, ports);
|
byt=null;
|
}else {
|
int size=data.getBytes().length;
|
Udp_Receive.udp_serch(data.getBytes(),size, ip, ports);
|
textArea.append(GetNowTime.now()+"·¢-->: "+data+"\n");
|
}
|
|
}
|
});
|
}
|
return sendButton;
|
|
}
|
|
|
|
public JComboBox<String> getBox() {
|
if(box==null) {
|
box=new JComboBox<String>();
|
String[] neixing= {"TCP Server","TCP Client","UDP"};
|
box.setFont(ChooseFont.getFont(12));//ÉèÖÃ×ÖÌå
|
ComboBoxModel<String > coModel=new DefaultComboBoxModel<>(neixing);//ÏÂÀÁбíÄ£ÐÍ
|
box.setModel(coModel);
|
box.setBackground(Color.white);
|
box.setSelectedIndex(2);
|
box.addActionListener(new ActionListener() {
|
public void actionPerformed(ActionEvent e) {
|
if(box.getSelectedIndex()==0) {
|
xieyi_type="1";
|
}else if(box.getSelectedIndex()==1) {
|
xieyi_type="2";
|
}else if(box.getSelectedIndex()==2) {
|
xieyi_type="3";
|
}else if(box.getSelectedIndex()==3) {
|
xieyi_type="4";
|
}
|
|
}
|
});
|
|
}
|
return box;
|
}
|
|
public JButtonModel getClear() {
|
if(clear==null) {
|
clear=new JButtonModel("Çå¿Õ");
|
clear.addActionListener(new ActionListener() {
|
@Override
|
public void actionPerformed(ActionEvent e) {
|
// TODO ×Ô¶¯Éú³ÉµÄ·½·¨´æ¸ù
|
textArea.setText("");
|
if(datatypeis.equals("µ÷ÊÔÊý¾Ý")) {
|
textArea.append(DebugStarMessage.getDebug().toString());
|
}
|
}
|
});
|
|
}
|
return clear;
|
}
|
|
|
public JComboBox<String> getTagbox() {
|
if(tagbox==null) {
|
tagbox=new JComboBox<String>();
|
tagbox.setFont(ChooseFont.getFont(12));//ÉèÖÃ×ÖÌå
|
ComboBoxModel<String > coModel=new DefaultComboBoxModel<>(Tag_Dell.get_tag_str());//ÏÂÀÁбíÄ£ÐÍ
|
tagbox.setModel(coModel);
|
tagbox.setBackground(Color.white);
|
tagbox.setEnabled(true);
|
//ÏÂÀ¿ò¿ÉÒÔÊäÈë
|
tagbox.setEditable(true);
|
tagbox.addActionListener(new ActionListener() {
|
@Override
|
public void actionPerformed(ActionEvent e) {
|
// TODO ×Ô¶¯Éú³ÉµÄ·½·¨´æ¸ù
|
need_guo_lv_tag=(String) tagbox.getSelectedItem();
|
|
}
|
});
|
}
|
return tagbox;
|
}
|
|
|
public static String getNeed_guo_lv_tag() {
|
return need_guo_lv_tag;
|
}
|
|
|
|
/**»ñÈ¡Êý¾ÝÀàÐÍ*/
|
public JComboBox<String> getDatatype() {
|
if(datatype==null) {
|
datatype=new JComboBox<String>();
|
datatype.setFont(ChooseFont.getFont(13));//ÉèÖÃ×ÖÌå
|
datatype.setForeground(Color.red);
|
String[] neir= {
|
"±¨ÎÄÊý¾Ý",
|
"ÔʼÊý¾Ý",
|
"URT¶Ë¿Ú",
|
"UDP¶Ë¿Ú",
|
"UDPת·¢",
|
"TCPת·¢",
|
"HTTPת·¢",
|
"×¢²á±¨ÎÄ",
|
"µ÷ÊÔÊý¾Ý",
|
"HEXÏÔʾ",
|
"Êý¾Ý¿âÊý",
|
"ÆøÌ屨ÎÄ",
|
"GNSS",
|
"55AA0C",
|
"55AA01",
|
"55AA02",
|
"55AA03",
|
"55AA07",
|
"55AA09",
|
"55AA0A",
|
"55AA10",
|
"55AA12",
|
"55AA14",
|
"55AA0E",
|
"TOANC",
|
"debug"};
|
ComboBoxModel<String > coModel=new DefaultComboBoxModel<>(neir);//ÏÂÀÁбíÄ£ÐÍ
|
datatype.setModel(coModel);
|
datatype.setBackground(Color.white);
|
datatype.setEnabled(true);
|
//ÏÂÀ¿ò¿ÉÒÔÊäÈë
|
datatype.setEditable(true);
|
datatype.addActionListener(new ActionListener() {
|
@Override
|
public void actionPerformed(ActionEvent e) {
|
// TODO ×Ô¶¯Éú³ÉµÄ·½·¨´æ¸ù
|
datatypeis=(String) datatype.getSelectedItem();
|
textArea.setText("");
|
if(openbaowen.isSelected()) {
|
Systems.alert_save_baowen(datatypeis, "1");
|
}
|
|
}
|
});
|
}
|
return datatype;
|
}
|
|
/**ÐèÒªÏÔʾµÄ±¨ÎÄÊý¾ÝÀàÐÍÊÇ*/
|
public static String getDatatypeis() {
|
return datatypeis;
|
}
|
|
|
public JCheckBoxModel getOpenbaowen() {
|
if(openbaowen==null) {
|
//¿ªÆô»òÕ߹رձ£´æ±¨Îĸ´Ñ¡¿ò
|
openbaowen=new JCheckBoxModel("×Ô¶¯±£´æ",Systems.sys().getOpensave());
|
openbaowen.setBackground(null);
|
openbaowen.addActionListener(new ActionListener() {
|
@Override
|
public void actionPerformed(ActionEvent e) {
|
if(openbaowen.isSelected()) {
|
Systems.alert_save_baowen(datatypeis, "1");
|
Systems.sys().setOpensave("1");
|
}else {
|
Systems.alert_save_baowen(datatypeis, "0");
|
Systems.sys().setOpensave("0");
|
}
|
|
}
|
});
|
}
|
return openbaowen;
|
}
|
|
public JCheckBoxModel getHexsend() {
|
if(hexsend==null) {
|
hexsend=new JCheckBoxModel("ASCLL½âÎö","0");
|
hexsend.setBackground(null);
|
hexsend.addActionListener(new ActionListener() {
|
public void actionPerformed(ActionEvent e) {
|
if(hexsend.isSelected()) {
|
asclljx=true;
|
}else {
|
asclljx=false;
|
}
|
|
}
|
});
|
|
}
|
return hexsend;
|
}
|
|
public JCheckBoxModel getHexins() {
|
if(hexins==null) {
|
hexins=new JCheckBoxModel("HEXÏÔʾ","0");
|
hexins.setBackground(null);
|
hexins.addActionListener(new ActionListener() {
|
public void actionPerformed(ActionEvent e) {
|
if(hexins.isSelected()) {
|
hexin=true;
|
}else {
|
hexin=false;
|
}
|
|
}
|
});
|
|
}
|
return hexins;
|
}
|
|
public static boolean isHexin() {
|
return hexin;
|
}
|
|
public JButtonModel getJbt_urt() {
|
if(jbt_urt==null) {
|
jbt_urt=new JButtonModel("¿ªÆôURT½ÓÊÕ");
|
jbt_urt.addActionListener(new ActionListener() {
|
public void actionPerformed(ActionEvent e) {
|
if(urt) {
|
urt=false;
|
jbt_urt.setText(" ÔÝÍ£URT½ÓÊÕ ");
|
}else {
|
urt=true;
|
jbt_urt.setText(" ¿ªÆôURT½ÓÊÕ ");
|
}
|
|
}
|
});
|
}
|
return jbt_urt;
|
}
|
|
public static boolean isUrt() {
|
return urt;
|
}
|
|
public static boolean isShowfrom() {
|
return showfrom;
|
}
|
|
public static void setShowfrom(boolean showfrom) {
|
TcpIpManage.showfrom = showfrom;
|
}
|
|
public static boolean isAsclljx() {
|
return asclljx;
|
}
|
|
|
}
|