/
AnalysisPane.java
112 lines (88 loc) · 3.62 KB
/
AnalysisPane.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
*
*/
package net.rec.contra.cjbe.editor.detail.attributes.code;
import net.rec.contra.cjbe.editor.AbstractDetailPane;
import net.rec.contra.cjbe.editor.BrowserInternalFrame;
import net.rec.contra.cjbe.editor.BrowserServices;
import net.rec.contra.cjbe.editor.BrowserTreeNode;
import org.apache.bcel.classfile.LineNumber;
import org.gjt.jclasslib.structures.ClassFile;
import org.gjt.jclasslib.structures.MethodInfo;
import org.gjt.jclasslib.structures.attributes.CodeAttribute;
import javax.swing.*;
import javax.swing.tree.TreePath;
import java.awt.*;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.util.HashMap;
// import javax.swing.undo.UndoManager;
public class AnalysisPane extends AbstractDetailPane implements FocusListener {
private HashMap<String, AnalysisDisplay> editPanes = new HashMap<String, AnalysisDisplay>();
private BrowserInternalFrame internalFrame;
public AnalysisPane(BrowserServices services) {
super(services);
internalFrame = (BrowserInternalFrame) services;
ClassFile classFile = services.getClassFile();
MethodInfo[] methods = classFile.getMethods();
this.setLayout(new CardLayout());
for (int i = 0; i < methods.length; i++) {
String methodIndex = Integer.toString(i);
//Integer methodIndex = new Integer(i);
for (int j = 0; j < methods[i].getAttributes().length; j++) {
if (methods[i].getAttributes()[j] instanceof CodeAttribute) {
addEditPane(methodIndex, classFile);
break;
}
}
}
}
private void addEditPane(String methodIndex, ClassFile classFile) {
AnalysisDisplay editArea = new AnalysisDisplay(Integer.parseInt(methodIndex), classFile, internalFrame);
//System.out.println(methodIndex);
//Scrollbar
JScrollPane scroll = new JScrollPane(editArea);
//LineNumberView view = new LineNumberView(editArea);
//scroll.setRowHeaderView(view);
scroll.getVerticalScrollBar().setValue(10);
this.add(scroll, methodIndex);
editPanes.put(methodIndex, editArea);
}
public void show(TreePath treePath) {
if (internalFrame.isReloading()) {
updateEditPanes();
}
//The panel's name is the index of the method in the panel
//It cannot be the name of the method since this isnt necessarily unique
String methodIndex = Integer.toString(((BrowserTreeNode) treePath.getParentPath().getLastPathComponent()).getIndex());
CardLayout cl = (CardLayout) this.getLayout();
cl.show(this, methodIndex);
}
private void updateEditPanes() {
internalFrame = (BrowserInternalFrame) services;
ClassFile classFile = services.getClassFile();
MethodInfo[] methods = classFile.getMethods();
for (int i = 0; i < methods.length; i++) {
String methodIndex = Integer.toString(i);
for (int j = 0; j < methods[i].getAttributes().length; j++) {
if (methods[i].getAttributes()[j] instanceof CodeAttribute) {
addEditPane(methodIndex, classFile);
break;
}
}
if (editPanes.get(methodIndex) == null) {
addEditPane(methodIndex, classFile);
}
//editPanes.get(methodIndex).setText("dfgh");
}
}
protected void setupComponent() {
}
public void focusGained(FocusEvent arg0) {
}
public void focusLost(FocusEvent arg0) {
}
public HashMap getEditPanes() {
return editPanes;
}
}