66import java .net .*;
77import javax .swing .*;
88import javax .swing .filechooser .FileFilter ;
9- import javax .swing .text .BadLocationException ;
10- import javax .swing .text .SimpleAttributeSet ;
11- import javax .swing .text .StyleConstants ;
12- import javax .swing .text .AbstractDocument ;
9+ import javax .swing .text .*;
1310import java .util .function .*;
1411import java .util .stream .*;
1512import io .github .javaherobrine .net .speed .*;
@@ -64,7 +61,7 @@ public class SocketUI extends JFrame implements Runnable{
6461 @ SuppressWarnings ("unused" )
6562 private static final Blocker ALLOW =new Blocker (false ,false ,i -> false );
6663 @ SuppressWarnings ("unused" )
67- private static final Blocker BLOCKED =new Blocker (true ,false ,i ->{ System . err . println ( "Hahaha" ); return true ;} );
64+ private static final Blocker BLOCKED =new Blocker (true ,false ,i ->true );
6865 private final Consumer <byte []> PASS_RETURN_VALUE =block ->{
6966 passed =true ;
7067 HEX_TEMP =block ;
@@ -681,8 +678,10 @@ public static void limit(LongConsumer u,LongConsumer d) {
681678 private static class HexView extends JFrame {
682679 public static final int LINE =20 ;
683680 private int line =0 ;
681+ private StringBuilder sb =new StringBuilder ();
684682 private static final long serialVersionUID = 1L ;
685683 private JTextPane pane ;
684+ private static final String LF =System .lineSeparator ();
686685 private static final SimpleAttributeSet RED =new SimpleAttributeSet (),BLUE =new SimpleAttributeSet (),GREEN =new SimpleAttributeSet ();
687686 @ SuppressWarnings ("unused" )
688687 public HexView () {
@@ -702,51 +701,48 @@ public HexView() {
702701 setDefaultCloseOperation (HIDE_ON_CLOSE );
703702 cls .addActionListener (n ->{
704703 pane .setText ("" );
704+ line =0 ;
705705 });
706706 data .add (cls );
707707 bar .add (data );
708708 setJMenuBar (bar );
709709 });
710710 }
711- private int newLine () {
711+ private String construct (byte [] data ) {
712+ for (byte b :data ) {
713+ sb .append (Hex .toHex (b ));
714+ sb .append (' ' );
715+ newLine ();
716+ }
717+ String str =sb .toString ();
718+ sb .setLength (0 );
719+ return str ;
720+ }
721+ private void newLine () {
712722 ++line ;
713723 if (line ==LINE ) {
714- try {
715- line =0 ;
716- pane .getDocument ().insertString (pane .getText ().length (),"\n " ,null );
717- return 1 ;
718- } catch (BadLocationException e ) {}
724+ line =0 ;
725+ sb .append (LF );
719726 }
720- return 0 ;
721727 }
722728 public void insertSend (byte [] str ) {
723729 try {
724- int offset =pane .getText ().length ();
725- for (int i =0 ;i <str .length ;++i ) {
726- pane .getDocument ().insertString (offset ,Hex .toHex (str [i ]),GREEN );
727- pane .getDocument ().insertString (offset +2 ," " ,GREEN );
728- offset +=3 ;
729- offset +=newLine ();
730- }
731- } catch (BadLocationException e ) {}
730+ Document doc =pane .getDocument ();
731+ doc .insertString (doc .getLength (),construct (str ), GREEN );
732+ } catch (BadLocationException e ) {
733+ e .printStackTrace ();
734+ }
732735 }
733736 public void insertRecv (int str ) {
734737 try {
735- int offset =pane .getText ().length ();
736- pane .getDocument ().insertString (offset , Hex .toHex ((byte )str ), BLUE );
737- pane .getDocument ().insertString (offset +2 , " " , BLUE );
738+ Document doc =pane .getDocument ();
739+ doc .insertString (doc .getLength (),construct (new byte [] {(byte )str }), BLUE );
738740 } catch (BadLocationException e ) {}
739- newLine ();
740741 }
741742 public void insertURG (byte [] str ) {
742743 try {
743- int offset =pane .getText ().length ();
744- for (int i =0 ;i <str .length ;++i ) {
745- pane .getDocument ().insertString (offset ,Hex .toHex (str [i ]),RED );
746- pane .getDocument ().insertString (offset +2 ," " ,RED );
747- offset +=3 ;
748- offset +=newLine ();
749- }
744+ Document doc =pane .getDocument ();
745+ doc .insertString (doc .getLength (),construct (str ), RED );
750746 } catch (BadLocationException e ) {}
751747 }
752748 }
0 commit comments