| | |
| | | import udptcp.UDPPortBReceiver; |
| | | |
| | | public class MessageViewPanel extends JPanel { |
| | | /** |
| | | * |
| | | */ |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | private ResourceBundle messages; // å½é
åæ¶æ¯èµæºå
|
| | | |
| | | // UIç»ä»¶å£°æ |
| | | private JButton btnStart, btnPause, btnClear, btnSend; // æ§å¶æé®ï¼å¼å§ãæåãæ¸
é¤ãåé |
| | | private static JComboBox<String> cbDataType; // 䏿æ¡ï¼æ°æ®ç±»åãåè®®ã设å¤ID |
| | | private ResourceBundle messages; |
| | | private JButton btnStart, btnPause, btnClear, btnSend; |
| | | private static JComboBox<String> cbDataType; |
| | | private static JComboBox<String> cbProtocol; |
| | | private static JComboBox<String> cbDeviceId; |
| | | private static JComboBox<String> cbRemoteDevice; // è¿ç¨è®¾å¤ä¸ææ¡ |
| | | private static JCheckBox chkAutoSave; // å¤éæ¡ï¼èªå¨ä¿åãæ¾ç¤ºæ¥æºãåå
è¿å¶æ¾ç¤ºãASCIIæ¾ç¤º |
| | | private static JComboBox<String> cbRemoteDevice; |
| | | private static JCheckBox chkAutoSave; |
| | | private static JCheckBox chkShowSource; |
| | | private static JCheckBox chkHexDisplay; |
| | | private static JCheckBox chkAsciiDisplay; |
| | | private static JTextArea txtDataView; // æ°æ®æ¾ç¤ºåºå |
| | | private JScrollPane scrollPane; // 带æ»å¨æ¡ç颿¿ |
| | | private JTextField txtSendData; // åéæ°æ®ææ¬æ¡ |
| | | private JRadioButton rdoSendHex; // HEXåéåéæé® |
| | | private JRadioButton rdoSendAscii; // ASCIIåéåéæé® |
| | | private JCheckBox chkAppendNewline; // å车æ¢è¡å¤éæ¡ |
| | | // æ·»å éæåéè·è¸ªçªå£å¯è§ç¶æ |
| | | private static JTextArea txtDataView; |
| | | private JScrollPane scrollPane; |
| | | private JTextField txtSendData; |
| | | private JRadioButton rdoSendHex; |
| | | private JRadioButton rdoSendAscii; |
| | | private JCheckBox chkAppendNewline; |
| | | |
| | | private static final ThreadLocal<StringBuilder> SB = |
| | | ThreadLocal.withInitial(() -> new StringBuilder(256)); |
| | | private static final char[] DIGITS = "0123456789".toCharArray(); |
| | | private static final String COLON = ":"; |
| | | private static final String PREFIX = "["; |
| | | private static final String SUFFIX = "]"; |
| | | |
| | | public static volatile boolean isWindowVisible = false; |
| | | // ç¶æåé |
| | | private static boolean isCapturing = false; // æ¯å¦æ£å¨æè·æ°æ®çæ å¿ |
| | | |
| | | // ä¿®æ¹ä¸ºMapåå¨è®¾å¤åå
¶æ¬å°ç«¯å£ |
| | | private static boolean isCapturing = false; |
| | | private static boolean isStarted = false; // æ°å¢ï¼è·è¸ªå¼å§æé®ç¶æ |
| | | |
| | | private static Map<String, Integer> remoteDeviceLocalPortMap = new HashMap<>(); |
| | | // æé 彿° |
| | | public MessageViewPanel(ResourceBundle messages) { |
| | | this.messages = messages; // åå§åæ¶æ¯èµæºå
|
| | | initializeUI(); // åå§åç¨æ·çé¢ |
| | | } |
| | | |
| | | |
| | | |
| | | public MessageViewPanel(ResourceBundle messages) { |
| | | this.messages = messages; |
| | | initializeUI(); |
| | | } |
| | | |
| | | public void addNotify() { |
| | | super.addNotify(); |
| | | Window window = SwingUtilities.getWindowAncestor(this); |
| | | if (window != null) { |
| | | isWindowVisible = true; // 颿¿å·²æ·»å å°å¯è§çªå£ |
| | | isWindowVisible = true; |
| | | window.addWindowListener(new WindowAdapter() { |
| | | @Override |
| | | public void windowClosing(WindowEvent e) { |
| | |
| | | } |
| | | } |
| | | |
| | | // åå§åUIç»ä»¶ |
| | | private void initializeUI() { |
| | | setLayout(new GridBagLayout()); // 使ç¨ç½æ ¼è¢å¸å± |
| | | GridBagConstraints gbc = new GridBagConstraints(); // å¸å±çº¦æå¯¹è±¡ |
| | | gbc.insets = new Insets(5, 10, 5, 10); // 设置ç»ä»¶é´è·ï¼ä¸ãå·¦ãä¸ãå³ï¼ |
| | | gbc.anchor = GridBagConstraints.WEST; // ç»ä»¶é å·¦å¯¹é½ |
| | | gbc.fill = GridBagConstraints.HORIZONTAL; // 水平填å
|
| | | setBackground(new Color(240, 245, 249)); // è®¾ç½®èæ¯è² |
| | | setLayout(new GridBagLayout()); |
| | | GridBagConstraints gbc = new GridBagConstraints(); |
| | | gbc.insets = new Insets(5, 10, 5, 10); |
| | | gbc.anchor = GridBagConstraints.WEST; |
| | | gbc.fill = GridBagConstraints.HORIZONTAL; |
| | | setBackground(new Color(240, 245, 249)); |
| | | |
| | | // 䏿æ¡åºå |
| | | gbc.gridx = 0; // èµ·å§å |
| | | gbc.gridy = 0; // èµ·å§è¡ |
| | | gbc.gridwidth = 1; // å ç¨1å宽度 |
| | | gbc.weightx = 0.25; // æ°´å¹³æé |
| | | gbc.gridx = 0; |
| | | gbc.gridy = 0; |
| | | gbc.gridwidth = 1; |
| | | gbc.weightx = 0.25; |
| | | |
| | | // æ°æ®ç±»å䏿æ¡é¢æ¿ |
| | | JPanel dataTypePanel = new JPanel(new BorderLayout(5, 0)); // 使ç¨è¾¹çå¸å± |
| | | dataTypePanel.setBackground(new Color(240, 245, 249)); // è®¾ç½®èæ¯è² |
| | | dataTypePanel.add(createLabel(messages.getString("MESSAGE_VIEW_DATA_TYPE")), BorderLayout.WEST); // æ·»å æ ç¾ |
| | | cbDataType = new JComboBox<>(); // åå»ºä¸ææ¡ |
| | | loadtyps();// æ·»å "ææç±»å"é项 |
| | | dataTypePanel.add(cbDataType, BorderLayout.CENTER); // å°ä¸ææ¡æ·»å å°é¢æ¿ä¸å¤® |
| | | add(dataTypePanel, gbc); // å°é¢æ¿æ·»å å°ä¸»é¢æ¿ |
| | | JPanel dataTypePanel = new JPanel(new BorderLayout(5, 0)); |
| | | dataTypePanel.setBackground(new Color(240, 245, 249)); |
| | | dataTypePanel.add(createLabel(messages.getString("MESSAGE_VIEW_DATA_TYPE")), BorderLayout.WEST); |
| | | cbDataType = new JComboBox<>(); |
| | | loadtyps(); |
| | | dataTypePanel.add(cbDataType, BorderLayout.CENTER); |
| | | add(dataTypePanel, gbc); |
| | | |
| | | // åè®®ä¸ææ¡ |
| | | gbc.gridx++; // ç§»å¨å°ä¸ä¸å |
| | | JPanel protocolPanel = new JPanel(new BorderLayout(5, 0)); // åè®®éæ©é¢æ¿ |
| | | protocolPanel.setBackground(new Color(240, 245, 249)); // è®¾ç½®èæ¯è² |
| | | protocolPanel.add(createLabel(messages.getString("MESSAGE_VIEW_PROTOCOL")), BorderLayout.WEST); // æ·»å åè®®æ ç¾ |
| | | cbProtocol = new JComboBox<>(new String[]{ // å建åè®®ä¸ææ¡å¹¶åå§åé项 |
| | | messages.getString("MESSAGE_VIEW_ALL_PROTOCOLS"), // ææåè®® |
| | | "UDP", // UDPåè®® |
| | | "TCP", // TCPåè®® |
| | | "MQTT", // MQTTåè®® |
| | | "HTTP" // HTTPåè®® |
| | | gbc.gridx++; |
| | | JPanel protocolPanel = new JPanel(new BorderLayout(5, 0)); |
| | | protocolPanel.setBackground(new Color(240, 245, 249)); |
| | | protocolPanel.add(createLabel(messages.getString("MESSAGE_VIEW_PROTOCOL")), BorderLayout.WEST); |
| | | cbProtocol = new JComboBox<>(new String[]{ |
| | | "ALL", |
| | | "55AA01", "55AA02", "55AA03", "55AA05", "55AA07", |
| | | "55AA0A", "55AA0C", "55AA12", "55AA14", "55AA20", |
| | | "GNGGA", "XTB" |
| | | }); |
| | | protocolPanel.add(cbProtocol, BorderLayout.CENTER); // å°ä¸ææ¡æ·»å å°é¢æ¿ä¸å¤® |
| | | add(protocolPanel, gbc); // å°é¢æ¿æ·»å å°ä¸»é¢æ¿ |
| | | protocolPanel.add(cbProtocol, BorderLayout.CENTER); |
| | | add(protocolPanel, gbc); |
| | | |
| | | // 设å¤IDä¸ææ¡ |
| | | gbc.gridx++; // ç§»å¨å°ä¸ä¸å |
| | | JPanel devicePanel = new JPanel(new BorderLayout(5, 0)); // 设å¤ID鿩颿¿ |
| | | devicePanel.setBackground(new Color(240, 245, 249)); // è®¾ç½®èæ¯è² |
| | | devicePanel.add(createLabel(messages.getString("MESSAGE_VIEW_DEVICE_ID")), BorderLayout.WEST); // æ·»å 设å¤IDæ ç¾ |
| | | cbDeviceId = new JComboBox<>(); // å建设å¤IDä¸ææ¡ |
| | | cbDeviceId.setEditable(true); // 设置为å¯ç¼è¾ï¼å
许æå¨è¾å
¥è®¾å¤ID |
| | | cbDeviceId.addItem(messages.getString("MESSAGE_VIEW_ALL_DEVICES")); // æ·»å "ææè®¾å¤"é项 |
| | | loadDeviceIds(); // å 载设å¤IDå表 |
| | | devicePanel.add(cbDeviceId, BorderLayout.CENTER); // å°ä¸ææ¡æ·»å å°é¢æ¿ä¸å¤® |
| | | add(devicePanel, gbc); // å°é¢æ¿æ·»å å°ä¸»é¢æ¿ |
| | | gbc.gridx++; |
| | | JPanel devicePanel = new JPanel(new BorderLayout(5, 0)); |
| | | devicePanel.setBackground(new Color(240, 245, 249)); |
| | | devicePanel.add(createLabel(messages.getString("MESSAGE_VIEW_DEVICE_ID")), BorderLayout.WEST); |
| | | cbDeviceId = new JComboBox<>(); |
| | | cbDeviceId.setEditable(true); |
| | | cbDeviceId.addItem("ALL"); |
| | | loadDeviceIds(); |
| | | devicePanel.add(cbDeviceId, BorderLayout.CENTER); |
| | | add(devicePanel, gbc); |
| | | |
| | | // è¿ç¨è®¾å¤ä¸ææ¡ |
| | | gbc.gridx++; // ç§»å¨å°ä¸ä¸å |
| | | JPanel remoteDevicePanel = new JPanel(new BorderLayout(5, 0)); // è¿ç¨è®¾å¤éæ©é¢æ¿ |
| | | remoteDevicePanel.setBackground(new Color(240, 245, 249)); // è®¾ç½®èæ¯è² |
| | | remoteDevicePanel.add(createLabel(messages.getString("MESSAGE_VIEW_REMOTE_DEVICE")), BorderLayout.WEST); // æ·»å è¿ç¨è®¾å¤æ ç¾ |
| | | cbRemoteDevice = new JComboBox<>(); // å建è¿ç¨è®¾å¤ä¸ææ¡ |
| | | cbRemoteDevice.setEditable(true); // 设置为å¯ç¼è¾ |
| | | cbRemoteDevice.addItem(messages.getString("MESSAGE_VIEW_ALL_DEVICES")); // æ·»å "ææè®¾å¤"é项 |
| | | remoteDevicePanel.add(cbRemoteDevice, BorderLayout.CENTER); // å°ä¸ææ¡æ·»å å°é¢æ¿ä¸å¤® |
| | | add(remoteDevicePanel, gbc); // å°é¢æ¿æ·»å å°ä¸»é¢æ¿ |
| | | gbc.gridx++; |
| | | JPanel remoteDevicePanel = new JPanel(new BorderLayout(5, 0)); |
| | | remoteDevicePanel.setBackground(new Color(240, 245, 249)); |
| | | remoteDevicePanel.add(createLabel(messages.getString("MESSAGE_VIEW_REMOTE_DEVICE")), BorderLayout.WEST); |
| | | cbRemoteDevice = new JComboBox<>(); |
| | | cbRemoteDevice.setEditable(true); |
| | | cbRemoteDevice.addItem(messages.getString("MESSAGE_VIEW_ALL_DEVICES")); |
| | | remoteDevicePanel.add(cbRemoteDevice, BorderLayout.CENTER); |
| | | add(remoteDevicePanel, gbc); |
| | | |
| | | // å¤éæ¡åºå |
| | | gbc.gridx = 0; // éç½®åä½ç½® |
| | | gbc.gridy++; // ç§»å¨å°ä¸ä¸è¡ |
| | | gbc.gridwidth = 4; // 横跨4å |
| | | gbc.weightx = 1.0; // æ°´å¹³æé |
| | | // å¤éæ¡åºå - ç®å为两个å¤éæ¡ |
| | | gbc.gridx = 0; |
| | | gbc.gridy++; |
| | | gbc.gridwidth = 4; |
| | | gbc.weightx = 1.0; |
| | | |
| | | JPanel checkboxPanel = new JPanel(new GridLayout(1, 4, 6, 0)); // åå»ºç½æ ¼å¸å±é¢æ¿ï¼1è¡4åï¼ |
| | | checkboxPanel.setBackground(new Color(240, 245, 249)); // è®¾ç½®èæ¯è² |
| | | chkAutoSave = createStyledCheckbox(messages.getString("MESSAGE_VIEW_AUTO_SAVE")); // å建èªå¨ä¿åå¤éæ¡ |
| | | chkShowSource = createStyledCheckbox(messages.getString("MESSAGE_VIEW_SHOW_SOURCE")); // å建æ¾ç¤ºæ¥æºå¤éæ¡ |
| | | chkHexDisplay = createStyledCheckbox(messages.getString("MESSAGE_VIEW_HEX_DISPLAY")); // å建åå
è¿å¶æ¾ç¤ºå¤éæ¡ |
| | | chkAsciiDisplay = createStyledCheckbox(messages.getString("MESSAGE_VIEW_ASCII_DISPLAY")); // å建ASCIIæ¾ç¤ºå¤éæ¡ |
| | | |
| | | // å°å¤éæ¡æ·»å å°é¢æ¿ |
| | | JPanel checkboxPanel = new JPanel(new GridLayout(1, 2, 6, 0)); // ä¿®æ¹ä¸º2å |
| | | checkboxPanel.setBackground(new Color(240, 245, 249)); |
| | | chkAutoSave = createStyledCheckbox(messages.getString("MESSAGE_VIEW_AUTO_SAVE")); |
| | | chkShowSource = createStyledCheckbox(messages.getString("MESSAGE_VIEW_SHOW_SOURCE")); |
| | | |
| | | // ç§»é¤äºåå
è¿å¶åASCIIæ¾ç¤ºå¤éæ¡ |
| | | checkboxPanel.add(chkAutoSave); |
| | | checkboxPanel.add(chkShowSource); |
| | | checkboxPanel.add(chkHexDisplay); |
| | | checkboxPanel.add(chkAsciiDisplay); |
| | | |
| | | add(checkboxPanel, gbc); // å°å¤éæ¡é¢æ¿æ·»å å°ä¸»é¢æ¿ |
| | | add(checkboxPanel, gbc); |
| | | |
| | | // æ°æ®æ¾ç¤ºåºå |
| | | gbc.gridy++; // ç§»å¨å°ä¸ä¸è¡ |
| | | gbc.weighty = 1.0; // åç´æé |
| | | gbc.fill = GridBagConstraints.BOTH; // ååå¡«å
|
| | | gbc.gridy++; |
| | | gbc.weighty = 1.0; |
| | | gbc.fill = GridBagConstraints.BOTH; |
| | | |
| | | txtDataView = new JTextArea(); // åå»ºææ¬åºå |
| | | txtDataView.setFont(new Font("Monospaced", Font.PLAIN, 14)); // 设置ç宽åä½ |
| | | txtDataView.setEditable(false); // 设置为ä¸å¯ç¼è¾ |
| | | scrollPane = new JScrollPane(txtDataView); // å建带æ»å¨æ¡ç颿¿ |
| | | txtDataView = new JTextArea(); |
| | | txtDataView.setFont(new Font("Monospaced", Font.PLAIN, 14)); |
| | | txtDataView.setEditable(false); |
| | | scrollPane = new JScrollPane(txtDataView); |
| | | scrollPane.setPreferredSize(new Dimension(800, 400)); |
| | | scrollPane.setBorder(BorderFactory.createTitledBorder( // 设置带æ é¢çè¾¹æ¡ |
| | | BorderFactory.createLineBorder(new Color(180, 180, 220)), // è¾¹æ¡é¢è² |
| | | messages.getString("MESSAGE_VIEW_DATA_PANEL"), // æ é¢ææ¬ |
| | | TitledBorder.LEFT, // æ é¢ä½ç½® |
| | | TitledBorder.TOP, // æ é¢ä½ç½® |
| | | new Font("微软é
é»", Font.BOLD, 12), // æ é¢åä½ |
| | | new Color(70, 130, 180) // æ é¢é¢è² |
| | | )); |
| | | scrollPane.setBorder(BorderFactory.createTitledBorder( |
| | | BorderFactory.createLineBorder(new Color(180, 180, 220)), |
| | | messages.getString("MESSAGE_VIEW_DATA_PANEL"), |
| | | TitledBorder.LEFT, |
| | | TitledBorder.TOP, |
| | | new Font("微软é
é»", Font.BOLD, 12), |
| | | new Color(70, 130, 180) |
| | | )); |
| | | |
| | | add(scrollPane, gbc); // å°æ»å¨é¢æ¿æ·»å å°ä¸»é¢æ¿ |
| | | add(scrollPane, gbc); |
| | | |
| | | // æé®é¢æ¿åºå |
| | | gbc.gridy++; // ç§»å¨å°ä¸ä¸è¡ |
| | | gbc.weighty = 0; // éç½®åç´æé |
| | | gbc.fill = GridBagConstraints.HORIZONTAL; // 水平填å
|
| | | gbc.gridy++; |
| | | gbc.weighty = 0; |
| | | gbc.fill = GridBagConstraints.HORIZONTAL; |
| | | |
| | | // æé®é¢æ¿ |
| | | JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 10, 5)); // ä½¿ç¨æµå¼å¸å±ï¼å·¦å¯¹é½ï¼ |
| | | buttonPanel.setBackground(new Color(240, 245, 249)); // è®¾ç½®èæ¯è² |
| | | btnStart = createStyledButton(messages.getString("MESSAGE_VIEW_START"), new Color(70, 130, 180)); // å建å¼å§æé®ï¼èè²ï¼ |
| | | btnPause = createStyledButton(messages.getString("MESSAGE_VIEW_PAUSE"), new Color(218, 165, 32)); // å建æåæé®ï¼éè²ï¼ |
| | | btnClear = createStyledButton(messages.getString("MESSAGE_VIEW_CLEAR"), new Color(205, 92, 92)); // å建æ¸
餿é®ï¼çº¢è²ï¼ |
| | | JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 10, 5)); |
| | | buttonPanel.setBackground(new Color(240, 245, 249)); |
| | | btnStart = createStyledButton(messages.getString("MESSAGE_VIEW_START"), new Color(70, 130, 180)); |
| | | btnPause = createStyledButton(messages.getString("MESSAGE_VIEW_PAUSE"), new Color(218, 165, 32)); |
| | | btnClear = createStyledButton(messages.getString("MESSAGE_VIEW_CLEAR"), new Color(205, 92, 92)); |
| | | |
| | | // åéç¸å
³æ§ä»¶ |
| | | txtSendData = new JTextField(30); // åéæ°æ®ææ¬æ¡ |
| | | txtSendData.setFont(new Font("微软é
é»", Font.PLAIN, 12)); // 设置åä½ |
| | | btnSend = createStyledButton(messages.getString("MESSAGE_VIEW_SEND"), new Color(60, 179, 113)); // å建åéæé®ï¼ç»¿è²ï¼ |
| | | txtSendData = new JTextField(30); |
| | | txtSendData.setFont(new Font("微软é
é»", Font.PLAIN, 12)); |
| | | btnSend = createStyledButton(messages.getString("MESSAGE_VIEW_SEND"), new Color(60, 179, 113)); |
| | | |
| | | // å建åéé项颿¿ |
| | | JPanel sendOptionsPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 5, 0)); |
| | | sendOptionsPanel.setBackground(new Color(240, 245, 249)); |
| | | |
| | | // å建åéæé®ç» |
| | | ButtonGroup sendFormatGroup = new ButtonGroup(); |
| | | |
| | | // å建HEXåéåéæé® |
| | | rdoSendHex = createStyledRadioButton(messages.getString("MESSAGE_VIEW_SEND_HEX")); |
| | | // å建ASCIIåéåéæé® |
| | | rdoSendAscii = createStyledRadioButton(messages.getString("MESSAGE_VIEW_SEND_ASCII")); |
| | | |
| | | // å°åéæé®æ·»å å°æé®ç» |
| | | sendFormatGroup.add(rdoSendHex); |
| | | sendFormatGroup.add(rdoSendAscii); |
| | | |
| | | // é»è®¤éä¸ASCIIåé |
| | | rdoSendAscii.setSelected(true); |
| | | |
| | | // å车æ¢è¡å¤éæ¡ |
| | | chkAppendNewline = createStyledCheckbox(messages.getString("MESSAGE_VIEW_APPEND_NEWLINE")); |
| | | |
| | | sendOptionsPanel.add(rdoSendHex); |
| | | sendOptionsPanel.add(rdoSendAscii); |
| | | sendOptionsPanel.add(chkAppendNewline); |
| | | |
| | | // 尿鮿·»å å°æé®é¢æ¿ |
| | | buttonPanel.add(btnStart); |
| | | buttonPanel.add(btnPause); |
| | | buttonPanel.add(btnClear); |
| | |
| | | buttonPanel.add(btnSend); |
| | | buttonPanel.add(sendOptionsPanel); |
| | | |
| | | add(buttonPanel, gbc); // å°æé®é¢æ¿æ·»å å°ä¸»é¢æ¿ |
| | | add(buttonPanel, gbc); |
| | | |
| | | // 设置æé®å¨ä½ |
| | | setupActions(); |
| | | } |
| | | |
| | | // åå»ºå¸¦æ ·å¼çæ ç¾ |
| | | private JLabel createLabel(String text) { |
| | | JLabel label = new JLabel(text); // å建æ ç¾ |
| | | label.setFont(new Font("微软é
é»", Font.BOLD, 12)); // 设置åä½ |
| | | label.setForeground(new Color(70, 70, 70)); // è®¾ç½®åæ¯è² |
| | | JLabel label = new JLabel(text); |
| | | label.setFont(new Font("微软é
é»", Font.BOLD, 12)); |
| | | label.setForeground(new Color(70, 70, 70)); |
| | | return label; |
| | | } |
| | | |
| | | // åå»ºå¸¦æ ·å¼çæé® |
| | | private JButton createStyledButton(String text, Color bgColor) { |
| | | JButton button = new JButton(text); // å建æé® |
| | | button.setFont(new Font("微软é
é»", Font.BOLD, 12)); // 设置åä½ |
| | | button.setBackground(bgColor); // è®¾ç½®èæ¯è² |
| | | button.setForeground(Color.WHITE); // è®¾ç½®åæ¯è²ï¼ç½è²ï¼ |
| | | button.setFocusPainted(false); // ç¦ç¨ç¦ç¹è¾¹æ¡ |
| | | button.setBorder(BorderFactory.createCompoundBorder( // 设置å¤åè¾¹æ¡ |
| | | BorderFactory.createLineBorder(bgColor.darker(), 1), // å¤é¨è¾¹æ¡ï¼æ·±è²ï¼ |
| | | BorderFactory.createEmptyBorder(5, 15, 5, 15) // å
é¨è¾¹è· |
| | | )); |
| | | JButton button = new JButton(text); |
| | | button.setFont(new Font("微软é
é»", Font.BOLD, 12)); |
| | | button.setBackground(bgColor); |
| | | button.setForeground(Color.WHITE); |
| | | button.setFocusPainted(false); |
| | | button.setBorder(BorderFactory.createCompoundBorder( |
| | | BorderFactory.createLineBorder(bgColor.darker(), 1), |
| | | BorderFactory.createEmptyBorder(5, 15, 5, 15) |
| | | )); |
| | | return button; |
| | | } |
| | | |
| | | // åå»ºå¸¦æ ·å¼çå¤éæ¡ |
| | | private JCheckBox createStyledCheckbox(String text) { |
| | | JCheckBox checkBox = new JCheckBox(text); // å建å¤éæ¡ |
| | | checkBox.setFont(new Font("微软é
é»", Font.PLAIN, 12)); // 设置åä½ |
| | | checkBox.setBackground(new Color(240, 245, 249)); // è®¾ç½®èæ¯è² |
| | | checkBox.setForeground(new Color(70, 70, 70)); // è®¾ç½®åæ¯è² |
| | | JCheckBox checkBox = new JCheckBox(text); |
| | | checkBox.setFont(new Font("微软é
é»", Font.PLAIN, 12)); |
| | | checkBox.setBackground(new Color(240, 245, 249)); |
| | | checkBox.setForeground(new Color(70, 70, 70)); |
| | | return checkBox; |
| | | } |
| | | |
| | | // åå»ºå¸¦æ ·å¼çåéæé® |
| | | private JRadioButton createStyledRadioButton(String text) { |
| | | JRadioButton radioButton = new JRadioButton(text); // å建åéæé® |
| | | radioButton.setFont(new Font("微软é
é»", Font.PLAIN, 12)); // 设置åä½ |
| | | radioButton.setBackground(new Color(240, 245, 249)); // è®¾ç½®èæ¯è² |
| | | radioButton.setForeground(new Color(70, 70, 70)); // è®¾ç½®åæ¯è² |
| | | |
| | | // ç¾åé䏿æ |
| | | JRadioButton radioButton = new JRadioButton(text); |
| | | radioButton.setFont(new Font("微软é
é»", Font.PLAIN, 12)); |
| | | radioButton.setBackground(new Color(240, 245, 249)); |
| | | radioButton.setForeground(new Color(70, 70, 70)); |
| | | radioButton.setIcon(new RadioButtonIcon(false)); |
| | | radioButton.setSelectedIcon(new RadioButtonIcon(true)); |
| | | |
| | | // æ·»å é¼ æ æ¬åææ |
| | | radioButton.addMouseListener(new java.awt.event.MouseAdapter() { |
| | | public void mouseEntered(java.awt.event.MouseEvent evt) { |
| | | radioButton.setForeground(new Color(30, 144, 255)); |
| | |
| | | radioButton.setForeground(new Color(70, 70, 70)); |
| | | } |
| | | }); |
| | | |
| | | return radioButton; |
| | | } |
| | | |
| | | // èªå®ä¹åéæé®å¾æ |
| | | private static class RadioButtonIcon implements Icon { |
| | | private static final int SIZE = 14; |
| | | private final boolean selected; |
| | |
| | | g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); |
| | | |
| | | if (selected) { |
| | | // éä¸ç¶æ - èè²å¡«å
|
| | | g2d.setColor(new Color(70, 130, 180)); |
| | | g2d.fillOval(x, y, SIZE, SIZE); |
| | | |
| | | // å
å - ç½è² |
| | | g2d.setColor(Color.WHITE); |
| | | g2d.fillOval(x + SIZE/4, y + SIZE/4, SIZE/2, SIZE/2); |
| | | } else { |
| | | // æªéä¸ç¶æ - ç°è²è¾¹æ¡ |
| | | g2d.setColor(new Color(150, 150, 150)); |
| | | g2d.drawOval(x, y, SIZE-1, SIZE-1); |
| | | } |
| | | |
| | | g2d.dispose(); |
| | | } |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | // å è½½æ°æ®ç±»å |
| | | private void loadtyps() { |
| | | cbDataType.removeAllItems(); |
| | | // æ·»å å½é
åé项 |
| | | cbDataType.addItem(messages.getString("MESSAGE_VIEW_ALL_TYPES")); |
| | | cbDataType.addItem(messages.getString("MESSAGE_VIEW_UDP_PORT_A")); |
| | | cbDataType.addItem(messages.getString("MESSAGE_VIEW_UDP_PORT_B")); |
| | | cbDataType.addItem(messages.getString("MESSAGE_VIEW_TCP_PORT")); |
| | | cbDataType.addItem(messages.getString("MESSAGE_VIEW_MQTT_PORT")); |
| | | cbDataType.addItem("UDPA"); |
| | | cbDataType.addItem("UDPB"); |
| | | cbDataType.addItem("TCP"); |
| | | } |
| | | |
| | | // 设置æé®å¨ä½ |
| | | private void setupActions() { |
| | | btnStart.addActionListener(e -> startCapture()); // å¼å§æé®ç»å®å¼å§æè·æ¹æ³ |
| | | btnPause.addActionListener(e -> pauseCapture()); // æåæé®ç»å®æåæè·æ¹æ³ |
| | | btnClear.addActionListener(e -> clearDisplay()); // æ¸
餿é®ç»å®æ¸
餿¾ç¤ºæ¹æ³ |
| | | btnSend.addActionListener(e -> sendData()); // åéæé®ç»å®åéæ¹æ³ |
| | | btnStart.addActionListener(e -> startCapture()); |
| | | btnPause.addActionListener(e -> pauseCapture()); |
| | | btnClear.addActionListener(e -> clearDisplay()); |
| | | btnSend.addActionListener(e -> sendData()); |
| | | } |
| | | |
| | | // å¼å§æè·æ°æ® |
| | | private void startCapture() { |
| | | if (!isCapturing) { // 妿å½åæªå¨æè·ç¶æ |
| | | isCapturing = true; // 设置æè·ç¶æä¸ºtrue |
| | | btnStart.setEnabled(false); // ç¦ç¨å¼å§æé® |
| | | btnPause.setEnabled(true); // å¯ç¨æåæé® |
| | | // å¯å¨æ°æ®æè·çº¿ç¨ |
| | | if (!isCapturing) { |
| | | isStarted = true; // 设置å¼å§æ å¿ |
| | | isCapturing = true; |
| | | btnStart.setEnabled(false); |
| | | btnPause.setEnabled(true); |
| | | } |
| | | } |
| | | |
| | | // æåæè·æ°æ® |
| | | private void pauseCapture() { |
| | | isCapturing = false; // 设置æè·ç¶æä¸ºfalse |
| | | btnStart.setEnabled(true); // å¯ç¨å¼å§æé® |
| | | btnPause.setEnabled(false); // ç¦ç¨æåæé® |
| | | isStarted = false; // æ¸
é¤å¼å§æ å¿ |
| | | isCapturing = false; |
| | | btnStart.setEnabled(true); |
| | | btnPause.setEnabled(false); |
| | | } |
| | | |
| | | // æ¸
餿°æ®æ¾ç¤º |
| | | private void clearDisplay() { |
| | | txtDataView.setText(""); // æ¸
ç©ºææ¬åºå |
| | | txtDataView.setText(""); |
| | | } |
| | | |
| | | // åéæ°æ®å°è¿ç¨è®¾å¤ |
| | | private void sendData() { |
| | | // ä½¿ç¨æ°æ¹æ³è·åå½åèµæºå
|
| | | ResourceBundle currentMessages = Languages.getCurrentMessages(); |
| | | ResourceBundle currentMessages = Languages.getCurrentMessages(); |
| | | String selectedDevice = (String) cbRemoteDevice.getSelectedItem(); |
| | | if (selectedDevice == null || selectedDevice.equals(currentMessages.getString("MESSAGE_VIEW_ALL_DEVICES"))) { |
| | | JOptionPane.showMessageDialog(this, |
| | | currentMessages.getString("MESSAGE_VIEW_SELECT_DEVICE"), |
| | | currentMessages.getString("WARNING"), |
| | | JOptionPane.showMessageDialog(this, |
| | | currentMessages.getString("MESSAGE_VIEW_SELECT_DEVICE"), |
| | | currentMessages.getString("WARNING"), |
| | | JOptionPane.WARNING_MESSAGE); |
| | | return; |
| | | } |
| | | |
| | | // è·åæ¬å°ç«¯å£ |
| | | Integer localPort = remoteDeviceLocalPortMap.get(selectedDevice); |
| | | if (localPort == null) { |
| | | JOptionPane.showMessageDialog(this, |
| | | JOptionPane.showMessageDialog(this, |
| | | "æ æ³ç¡®å®è®¾å¤çæ¥æ¶ç«¯å£", |
| | | currentMessages.getString("ERROR"), |
| | | currentMessages.getString("ERROR"), |
| | | JOptionPane.ERROR_MESSAGE); |
| | | return; |
| | | } |
| | | |
| | | // è§£æIPåç«¯å£ |
| | | String[] parts = selectedDevice.split(":"); |
| | | if (parts.length != 2) { |
| | | JOptionPane.showMessageDialog(this, |
| | | currentMessages.getString("MESSAGE_VIEW_INVALID_DEVICE"), |
| | | currentMessages.getString("ERROR"), |
| | | JOptionPane.showMessageDialog(this, |
| | | currentMessages.getString("MESSAGE_VIEW_INVALID_DEVICE"), |
| | | currentMessages.getString("ERROR"), |
| | | JOptionPane.ERROR_MESSAGE); |
| | | return; |
| | | } |
| | |
| | | try { |
| | | port = Integer.parseInt(parts[1]); |
| | | } catch (NumberFormatException ex) { |
| | | JOptionPane.showMessageDialog(this, |
| | | currentMessages.getString("MESSAGE_VIEW_INVALID_PORT"), |
| | | currentMessages.getString("ERROR"), |
| | | JOptionPane.showMessageDialog(this, |
| | | currentMessages.getString("MESSAGE_VIEW_INVALID_PORT"), |
| | | currentMessages.getString("ERROR"), |
| | | JOptionPane.ERROR_MESSAGE); |
| | | return; |
| | | } |
| | | |
| | | String dataToSend = txtSendData.getText(); |
| | | if (dataToSend.isEmpty()) { |
| | | JOptionPane.showMessageDialog(this, |
| | | currentMessages.getString("MESSAGE_VIEW_EMPTY_DATA"), |
| | | currentMessages.getString("WARNING"), |
| | | JOptionPane.showMessageDialog(this, |
| | | currentMessages.getString("MESSAGE_VIEW_EMPTY_DATA"), |
| | | currentMessages.getString("WARNING"), |
| | | JOptionPane.WARNING_MESSAGE); |
| | | return; |
| | | } |
| | | |
| | | // æ·»å å车æ¢è¡ |
| | | if (chkAppendNewline.isSelected()) { |
| | | dataToSend += "\r\n"; |
| | | } |
| | | |
| | | // è®°å½åéæ°æ®å°çé¢ |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | String timestamp = sdf.format(new Date()); |
| | | |
| | |
| | | displayData.append("[SEND][").append(timestamp).append("][").append(ip).append(":").append(port).append("] "); |
| | | |
| | | if (rdoSendHex.isSelected()) { |
| | | // HEXæ ¼å¼åé |
| | | String hexData = toHexString(dataToSend); |
| | | displayData.append(hexData); |
| | | if (localPort == UDPPortAReceiver.PORT) { |
| | | // ä¼ å
¥æ¯å¦HEXåéçæ å¿ |
| | | UDPPortAReceiver.sendData(ip, port, dataToSend, true); |
| | | } else if (localPort == UDPPortBReceiver.PORT) { |
| | | // ä¼ å
¥æ¯å¦HEXåéçæ å¿ |
| | | UDPPortBReceiver.sendData(ip, port, dataToSend, true); |
| | | } |
| | | |
| | | } else { |
| | | // ASCIIæ ¼å¼åé |
| | | displayData.append(dataToSend); |
| | | // å®é
åéASCIIæ°æ®ï¼è¿ééè¦è°ç¨UDPåéæ¹æ³ï¼ |
| | | if (localPort == UDPPortAReceiver.PORT) { |
| | | UDPPortAReceiver.sendData(ip, port, dataToSend, false); |
| | | } else if (localPort == UDPPortBReceiver.PORT) { |
| | |
| | | } |
| | | } |
| | | |
| | | // å¨EDT线ç¨ä¸æ´æ°UI |
| | | SwingUtilities.invokeLater(() -> { |
| | | txtDataView.append(displayData.toString() + "\n"); |
| | | // èªå¨æ»å¨å°åºé¨ |
| | | txtDataView.setCaretPosition(txtDataView.getDocument().getLength()); |
| | | }); |
| | | } |
| | | |
| | | // ä¿®æ¹æ·»å è¿ç¨è®¾å¤æ¹æ³ |
| | | // å¨MessageViewPanelç±»ä¸ä¿®æ¹addRemoteDeviceæ¹æ³ |
| | | public static void addRemoteDevice(String ip, int port, int localPort) { |
| | | String device = ip + ":" + port; |
| | | if (!remoteDeviceLocalPortMap.containsKey(device)) { |
| | | remoteDeviceLocalPortMap.put(device, localPort); |
| | | SwingUtilities.invokeLater(() -> { |
| | | // æ£æ¥ä¸ææ¡ä¸æ¯å¦å·²åå¨è¯¥è®¾å¤ |
| | | boolean exists = false; |
| | | ComboBoxModel<String> model = cbRemoteDevice.getModel(); |
| | | for (int i = 0; i < model.getSize(); i++) { |
| | |
| | | } |
| | | } |
| | | |
| | | // æè·æ°æ®çæ ¸å¿æ¹æ³ |
| | | // ä¿®æ¹éç¨æ°æ®æ¾ç¤ºæ¹æ³ |
| | | public static void showData(String rawData, String ip, int port, int localPort, String deviceId) { |
| | | if (!isWindowVisible) { |
| | | public static void showData(String rawData, String ip, int port, int localPort, |
| | | String DataType, String Protocol, String Id) { |
| | | // å鿣æ¥ï¼çªå£å¯è§ä¸å·²ç¹å»å¼å§æé® |
| | | if (!isWindowVisible || !isStarted) { |
| | | return; |
| | | } |
| | | |
| | | // è·åå½åéæ© |
| | | |
| | | if (cbDataType == null || cbProtocol == null || cbDeviceId == null) { |
| | | return; |
| | | } |
| | | |
| | | String selectedDataType = (String) cbDataType.getSelectedItem(); |
| | | String selectedProtocol = (String) cbProtocol.getSelectedItem(); |
| | | String selectedDeviceId = (String) cbDeviceId.getSelectedItem(); |
| | | |
| | | // ä½¿ç¨æ°æ¹æ³è·åå½åèµæºå
|
| | | ResourceBundle messages = Languages.getCurrentMessages(); |
| | | boolean DataTypeboolean = "ALL".equals(selectedDataType) || selectedDataType.equals(DataType); |
| | | boolean Protocolboolean = "ALL".equals(selectedProtocol) || selectedProtocol.equals(Protocol); |
| | | boolean DeviceIdboolean = "ALL".equals(selectedDeviceId) || selectedDeviceId.equals(Id); |
| | | |
| | | String allTypes = messages.getString("MESSAGE_VIEW_ALL_TYPES"); |
| | | String allProtocols = messages.getString("MESSAGE_VIEW_ALL_PROTOCOLS"); |
| | | String allDevices = messages.getString("MESSAGE_VIEW_ALL_DEVICES"); |
| | | String udpPortA = messages.getString("MESSAGE_VIEW_UDP_PORT_A"); |
| | | String udpPortB = messages.getString("MESSAGE_VIEW_UDP_PORT_B"); |
| | | String udpProtocol = "UDP"; // ç´æ¥ä½¿ç¨åè®®åç§° |
| | | if (DataTypeboolean && Protocolboolean && DeviceIdboolean) { |
| | | StringBuilder sb = SB.get(); |
| | | sb.setLength(0); |
| | | |
| | | // æ£æ¥æ°æ®ç±»åè¿æ»¤ |
| | | boolean dataTypeMatch = selectedDataType.equals(allTypes) || |
| | | (localPort == UDPPortAReceiver.PORT && selectedDataType.equals(udpPortA)) || |
| | | (localPort == UDPPortBReceiver.PORT && selectedDataType.equals(udpPortB)); |
| | | if (chkShowSource.isSelected()) { |
| | | sb.append(PREFIX); |
| | | formatTime(sb); |
| | | sb.append(',').append(ip).append(COLON).append(port).append(SUFFIX); |
| | | } |
| | | sb.append(rawData); |
| | | |
| | | // æ£æ¥åè®®è¿æ»¤ |
| | | boolean protocolMatch = selectedProtocol.equals(allProtocols) || |
| | | (localPort == UDPPortAReceiver.PORT && selectedProtocol.equals(udpProtocol)) || |
| | | (localPort == UDPPortBReceiver.PORT && selectedProtocol.equals(udpProtocol)); |
| | | |
| | | // æ£æ¥è®¾å¤IDè¿æ»¤ |
| | | boolean deviceIdMatch=false; |
| | | if("1".equals(deviceId)) { |
| | | deviceIdMatch=true; |
| | | }else { |
| | | deviceIdMatch = selectedDeviceId.equals(allDevices) || |
| | | (deviceId != null && deviceId.equals(selectedDeviceId)); |
| | | } |
| | | |
| | | // åªæå½æææ¡ä»¶é½å¹é
æ¶ææ¾ç¤º |
| | | if (!(dataTypeMatch && protocolMatch && deviceIdMatch)) { |
| | | return; |
| | | } |
| | | |
| | | // çææ¯«ç§çº§æ¶é´æ³ |
| | | SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss.SSS"); |
| | | String timestamp = sdf.format(new Date()); |
| | | String formattedData = formatData(rawData, ip, port, timestamp); |
| | | |
| | | if (isCapturing) { |
| | | // æ·»å è¿ç¨è®¾å¤å°ä¸ææ¡ |
| | | addRemoteDevice(ip, port, localPort); |
| | | |
| | | // å¨EDT线ç¨ä¸æ´æ°UI |
| | | final String finalText = sb.toString(); |
| | | SwingUtilities.invokeLater(() -> { |
| | | txtDataView.append(formattedData + "\n"); |
| | | txtDataView.append(finalText); |
| | | txtDataView.append("\n"); |
| | | txtDataView.setCaretPosition(txtDataView.getDocument().getLength()); |
| | | }); |
| | | } |
| | | |
| | | // 妿å¯ç¨äºèªå¨ä¿åï¼åä¿åå°æä»¶ |
| | | if (chkAutoSave.isSelected()) { |
| | | saveToFile(formattedData); |
| | | if (isCapturing && localPort != 0) { |
| | | addRemoteDevice(ip, port, localPort); |
| | | } |
| | | |
| | | if (chkAutoSave.isSelected()) { |
| | | saveToFile(finalText); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // æ ¼å¼åæ°æ®æ¾ç¤º |
| | | // ä¿®æ¹æ ¼å¼æ¾ç¤ºæ¹æ³ï¼æ¯ææ··åæ ¼å¼ |
| | | private static String formatData(String rawData, String ip, int port, String timestamp) { |
| | | StringBuilder formatted = new StringBuilder(); |
| | | // ä½¿ç¨æ°æ¹æ³è·åå½åèµæºå
|
| | | ResourceBundle messages = Languages.getCurrentMessages(); |
| | | // æ¾ç¤ºæ¥æºä¿¡æ¯ |
| | | if (chkShowSource.isSelected()) { |
| | | formatted.append("[") |
| | | .append(timestamp) |
| | | .append("][") |
| | | .append(ip) |
| | | .append(":") |
| | | .append(port) |
| | | .append("] "); |
| | | } |
| | | |
| | | // æ ¹æ®æ¾ç¤ºéé¡¹æ ¼å¼åæ°æ® |
| | | if (chkHexDisplay.isSelected() && chkAsciiDisplay.isSelected()) { |
| | | formatted.append(formatHexString(rawData)) |
| | | .append(" | ") |
| | | .append(hexToAscii(rawData)) |
| | | .append(" [") |
| | | .append(messages.getString("MESSAGE_VIEW_MIXED_FORMAT")) |
| | | .append("]"); |
| | | } else if (chkHexDisplay.isSelected()) { |
| | | formatted.append(formatHexString(rawData)) |
| | | .append(" [") |
| | | .append(messages.getString("MESSAGE_VIEW_HEX_FORMAT")) |
| | | .append("]"); |
| | | } else if (chkAsciiDisplay.isSelected()) { |
| | | formatted.append(hexToAscii(rawData)) |
| | | .append(" [") |
| | | .append(messages.getString("MESSAGE_VIEW_ASCII_FORMAT")) |
| | | .append("]"); |
| | | } else { |
| | | formatted.append(hexToAscii(rawData)); |
| | | } |
| | | |
| | | return formatted.toString(); |
| | | } |
| | | |
| | | // ä¿®æ¹è®¾å¤IDå è½½æ¹æ³ |
| | | private void loadDeviceIds() { |
| | | cbDeviceId.removeAllItems(); |
| | | cbDeviceId.addItem(messages.getString("MESSAGE_VIEW_ALL_DEVICES")); |
| | | cbDeviceId.addItem("ALL"); |
| | | |
| | | List<String> tags = Dell_tag.getAlldeviceIds(); |
| | | for (String tag : tags) { |
| | |
| | | } |
| | | } |
| | | |
| | | // å°å符串转æ¢ä¸ºåå
è¿å¶è¡¨ç¤º |
| | | private static String toHexString(String input) { |
| | | StringBuilder hex = new StringBuilder(); // 使ç¨StringBuilderæå»ºåå
è¿å¶å符串 |
| | | for (char c : input.toCharArray()) { // éåæ¯ä¸ªå符 |
| | | hex.append(String.format("%02X ", (int) c)); // æ ¼å¼å为两ä½åå
è¿å¶ |
| | | StringBuilder hex = new StringBuilder(); |
| | | for (char c : input.toCharArray()) { |
| | | hex.append(String.format("%02X ", (int) c)); |
| | | } |
| | | return hex.toString().trim(); // è¿åå¹¶å»é¤æ«å°¾ç©ºæ ¼ |
| | | } |
| | | // æ ¼å¼ååå
è¿å¶åç¬¦ä¸²ï¼æ¯ä¸¤ä¸ªå符å ç©ºæ ¼ï¼ |
| | | private static String formatHexString(String hex) { |
| | | StringBuilder formatted = new StringBuilder(); |
| | | for (int i = 0; i < hex.length(); i += 2) { |
| | | if (i > 0) formatted.append(" "); |
| | | formatted.append(hex.substring(i, Math.min(i + 2, hex.length()))); |
| | | } |
| | | return formatted.toString(); |
| | | return hex.toString().trim(); |
| | | } |
| | | |
| | | // å°åå
è¿å¶å符串转æ¢ä¸ºASCII |
| | | private static String hexToAscii(String hexStr) { |
| | | StringBuilder output = new StringBuilder(); |
| | | for (int i = 0; i < hexStr.length(); i += 2) { |
| | | String str = hexStr.substring(i, i + 2); |
| | | output.append((char) Integer.parseInt(str, 16)); |
| | | } |
| | | return output.toString(); |
| | | } |
| | | // ä¿åæ°æ®å°æä»¶ |
| | | private static void saveToFile(String data) { |
| | | SimpleDateFormat fileFormat = new SimpleDateFormat("yyyyMMdd"); // æä»¶æ¥ææ ¼å¼ |
| | | String fileName = "systemfile/baowen/messages_" + fileFormat.format(new Date()) + ".txt"; // æä»¶åå
嫿¥æ |
| | | SimpleDateFormat fileFormat = new SimpleDateFormat("yyyyMMdd"); |
| | | String fileName = "systemfile/baowen/messages_" + fileFormat.format(new Date()) + ".txt"; |
| | | |
| | | try (java.io.FileWriter writer = new java.io.FileWriter(fileName, true)) { // 使ç¨è¿½å æ¨¡å¼ |
| | | writer.write(data + "\n"); // åå
¥æ°æ®å¹¶æ¢è¡ |
| | | try (java.io.FileWriter writer = new java.io.FileWriter(fileName, true)) { |
| | | writer.write(data + "\n"); |
| | | } catch (java.io.IOException ex) { |
| | | ex.printStackTrace(); // æå°IOå¼å¸¸ |
| | | ex.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | public static String getSelectedDataType() { |
| | | return cbDataType == null ? "" : String.valueOf(cbDataType.getSelectedItem()); |
| | | } |
| | | |
| | | public static String getSelectedProtocol() { |
| | | return cbProtocol == null ? "" : String.valueOf(cbProtocol.getSelectedItem()); |
| | | } |
| | | |
| | | public static String getSelectedDeviceId() { |
| | | return cbDeviceId == null ? "" : String.valueOf(cbDeviceId.getSelectedItem()); |
| | | } |
| | | |
| | | private static void formatTime(StringBuilder sb) { |
| | | long now = System.currentTimeMillis(); |
| | | long sec = (now / 1000) % 86400; |
| | | int ms = (int) (now % 1000); |
| | | |
| | | int h = (int) (sec / 3600); |
| | | int m = (int) ((sec % 3600) / 60); |
| | | int s = (int) (sec % 60); |
| | | |
| | | sb.append((char) ('0' + (h / 10))) |
| | | .append((char) ('0' + (h % 10))).append(':'); |
| | | sb.append((char) ('0' + (m / 10))) |
| | | .append((char) ('0' + (m % 10))).append(':'); |
| | | sb.append((char) ('0' + (s / 10))) |
| | | .append((char) ('0' + (s % 10))).append('.'); |
| | | sb.append(DIGITS[ms / 100]) |
| | | .append(DIGITS[(ms / 10) % 10]) |
| | | .append(DIGITS[ms % 10]); |
| | | } |
| | | } |