Skip to content

Commit e756324

Browse files
committed
[Go-To] Move caret to requested field.
- Also added enum constant declarations to the token parser.
1 parent afeab95 commit e756324

7 files changed

Lines changed: 478 additions & 338 deletions

File tree

src/main/java/the/bytecode/club/bytecodeviewer/gui/components/SearchableRSyntaxTextArea.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@
3030
import javax.swing.*;
3131
import javax.swing.text.BadLocationException;
3232
import java.awt.*;
33-
import java.awt.event.InputEvent;
34-
import java.awt.event.KeyEvent;
35-
import java.awt.event.MouseWheelEvent;
33+
import java.awt.event.*;
3634

3735
/**
3836
* Searching on an RSyntaxTextArea using swing highlighting
@@ -87,6 +85,24 @@ public SearchableRSyntaxTextArea()
8785
GlobalHotKeys.keyPressed(keyEvent);
8886
}));
8987

88+
setCursor(new Cursor(Cursor.TEXT_CURSOR));
89+
getCaret().setBlinkRate(0);
90+
getCaret().setVisible(true);
91+
addFocusListener(new FocusAdapter()
92+
{
93+
@Override
94+
public void focusGained(FocusEvent e)
95+
{
96+
getCaret().setVisible(true);
97+
}
98+
99+
@Override
100+
public void focusLost(FocusEvent e)
101+
{
102+
getCaret().setVisible(true);
103+
}
104+
});
105+
90106
final Font newFont = getFont().deriveFont((float) BytecodeViewer.viewer.getFontSize());
91107

92108
//set number-bar font

src/main/java/the/bytecode/club/bytecodeviewer/gui/components/actions/GoToAction.java

Lines changed: 86 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
package the.bytecode.club.bytecodeviewer.gui.components.actions;
22

33
import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;
4-
import org.fife.ui.rsyntaxtextarea.Token;
5-
import org.objectweb.asm.tree.ClassNode;
64
import 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;
78
import the.bytecode.club.bytecodeviewer.resources.ResourceContainer;
89
import the.bytecode.club.bytecodeviewer.resources.classcontainer.ClassFileContainer;
910
import the.bytecode.club.bytecodeviewer.resources.classcontainer.locations.ClassFieldLocation;
10-
import the.bytecode.club.bytecodeviewer.resources.classcontainer.parser.TokenUtil;
1111

1212
import javax.swing.*;
13+
import javax.swing.event.CaretEvent;
14+
import javax.swing.event.CaretListener;
1315
import javax.swing.text.Element;
1416
import 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
}

src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/Workspace.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import the.bytecode.club.bytecodeviewer.gui.resourceviewer.viewer.FileViewer;
2525
import the.bytecode.club.bytecodeviewer.gui.resourceviewer.viewer.ResourceViewer;
2626
import the.bytecode.club.bytecodeviewer.resources.ResourceContainer;
27+
import the.bytecode.club.bytecodeviewer.resources.classcontainer.ClassFileContainer;
2728
import the.bytecode.club.bytecodeviewer.translation.TranslatedComponents;
2829
import the.bytecode.club.bytecodeviewer.translation.TranslatedStrings;
2930
import the.bytecode.club.bytecodeviewer.translation.components.TranslatedJButton;
@@ -33,13 +34,10 @@
3334

3435
import javax.swing.*;
3536
import java.awt.*;
36-
import java.awt.event.MouseEvent;
37-
import java.awt.event.MouseListener;
37+
import java.util.HashMap;
3838
import java.util.HashSet;
3939
import java.util.Set;
4040

41-
import static the.bytecode.club.bytecodeviewer.Constants.BLOCK_TAB_MENU;
42-
4341
/**
4442
* This pane contains all the resources, as tabs.
4543
*
@@ -54,6 +52,7 @@ public class Workspace extends TranslatedVisibleComponent {
5452
public final JPanel buttonPanel;
5553
public final JButton refreshClass;
5654
public final Set<String> openedTabs = new HashSet<>();
55+
public HashMap<String, ClassFileContainer> classFiles = new HashMap<>();
5756

5857
public Workspace() {
5958
super("Workspace", TranslatedComponents.WORK_SPACE);

0 commit comments

Comments
 (0)