11package the .bytecode .club .bytecodeviewer .gui .components .actions ;
22
33import org .fife .ui .rsyntaxtextarea .RSyntaxTextArea ;
4- import org .fife .ui .rsyntaxtextarea .Token ;
5- import org .objectweb .asm .tree .ClassNode ;
64import the .bytecode .club .bytecodeviewer .BytecodeViewer ;
5+ import the .bytecode .club .bytecodeviewer .gui .resourceviewer .BytecodeViewPanel ;
6+ import the .bytecode .club .bytecodeviewer .gui .resourceviewer .viewer .ClassViewer ;
7+ import the .bytecode .club .bytecodeviewer .gui .util .BytecodeViewPanelUpdater ;
78import the .bytecode .club .bytecodeviewer .resources .ResourceContainer ;
89import the .bytecode .club .bytecodeviewer .resources .classcontainer .ClassFileContainer ;
910import the .bytecode .club .bytecodeviewer .resources .classcontainer .locations .ClassFieldLocation ;
10- import the .bytecode .club .bytecodeviewer .resources .classcontainer .parser .TokenUtil ;
1111
1212import javax .swing .*;
13+ import javax .swing .event .CaretEvent ;
14+ import javax .swing .event .CaretListener ;
1315import javax .swing .text .Element ;
1416import java .awt .event .ActionEvent ;
17+ import java .util .HashMap ;
1518
1619/**
1720 * Created by Bl3nd.
@@ -36,20 +39,14 @@ public void actionPerformed(ActionEvent e)
3639 container .fieldMembers .values ().forEach (fields -> fields .forEach (field -> {
3740 if (field .line == line && field .columnStart - 1 <= column && field .columnEnd >= column )
3841 {
42+ Element root = textArea .getDocument ().getDefaultRootElement ();
3943 // Open the class that is associated with the field's owner.
4044 if (!field .owner .equals (container .getName ()))
4145 {
42- ResourceContainer resourceContainer = BytecodeViewer .getFileContainer (container .getParentContainer ());
43- if (resourceContainer != null )
44- {
45- String s = container .getImport (field .owner );
46- BytecodeViewer .viewer .workPane .addClassResource (resourceContainer , s + ".class" );
47- }
48-
46+ openFieldClass (field , textArea );
4947 return ;
5048 }
5149
52- Element root = textArea .getDocument ().getDefaultRootElement ();
5350 ClassFieldLocation first = fields .get (0 );
5451 int startOffset = root .getElement (first .line - 1 ).getStartOffset () + (first .columnStart - 1 );
5552 textArea .setCaretPosition (startOffset );
@@ -100,4 +97,82 @@ public void actionPerformed(ActionEvent e)
10097 }
10198 }));
10299 }
100+
101+ private void openFieldClass (ClassFieldLocation field , RSyntaxTextArea textArea )
102+ {
103+ String token = textArea .modelToToken (textArea .getCaretPosition ()).getLexeme ();
104+ ResourceContainer resourceContainer = BytecodeViewer .getFileContainer (container .getParentContainer ());
105+ if (resourceContainer != null )
106+ {
107+ String s = container .getImport (field .owner );
108+ BytecodeViewer .viewer .workPane .addClassResource (resourceContainer , s + ".class" );
109+ ClassViewer activeResource = (ClassViewer ) BytecodeViewer .viewer .workPane .getActiveResource ();
110+ HashMap <String , ClassFileContainer > classFiles = BytecodeViewer .viewer .workPane .classFiles ;
111+ Thread thread = new Thread (() -> {
112+ try
113+ {
114+ BytecodeViewer .updateBusyStatus (true );
115+ Thread .sleep (1000 );
116+ } catch (InterruptedException e )
117+ {
118+ throw new RuntimeException (e );
119+ } finally
120+ {
121+ BytecodeViewer .updateBusyStatus (false );
122+ }
123+
124+ String s2 = activeResource .resource .workingName + "-" + this .container .getDecompiler ();
125+ ClassFileContainer classFileContainer = classFiles .get (s2 );
126+ classFileContainer .fieldMembers .forEach ((field1 , field2 ) -> {
127+ if (field1 .equals (token ))
128+ {
129+ field2 .forEach (classFieldLocation -> {
130+ if (classFieldLocation .type .equals ("declaration" ))
131+ {
132+ for (int i = 0 ; i < 3 ; i ++)
133+ {
134+ BytecodeViewPanel panel = activeResource .getPanel (i );
135+ if (panel .textArea != null )
136+ {
137+ if (panel .decompiler .getDecompilerName ().equals (this .container .getDecompiler ()))
138+ {
139+ Element root = panel .textArea .getDocument ().getDefaultRootElement ();
140+ int startOffset = root .getElement (classFieldLocation .line - 1 ).getStartOffset () + (classFieldLocation .columnStart - 1 );
141+ panel .textArea .setCaretPosition (startOffset );
142+ for (CaretListener caretListener : panel .textArea .getCaretListeners ())
143+ {
144+ if (caretListener instanceof BytecodeViewPanelUpdater .MarkerCaretListener )
145+ {
146+ BytecodeViewPanelUpdater .MarkerCaretListener markerCaretListener = (BytecodeViewPanelUpdater .MarkerCaretListener ) caretListener ;
147+ markerCaretListener .caretUpdate (new CaretEvent (panel .textArea )
148+ {
149+ @ Override
150+ public int getDot ()
151+ {
152+ return panel .textArea .getCaret ().getDot ();
153+ }
154+
155+ @ Override
156+ public int getMark ()
157+ {
158+ return 0 ;
159+ }
160+ });
161+ }
162+ }
163+
164+ panel .textArea .requestFocusInWindow ();
165+
166+ break ;
167+ }
168+ }
169+ }
170+ }
171+ });
172+ }
173+ });
174+ });
175+ thread .start ();
176+ }
177+ }
103178}
0 commit comments