mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-09-25 21:10:46 +00:00
AS3 Two sided Highlighting, Edit/Cancel button
This commit is contained in:
@@ -29,21 +29,47 @@ import java.awt.event.MouseListener;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import javax.swing.event.CaretEvent;
|
||||
import javax.swing.event.CaretListener;
|
||||
|
||||
public class DecompiledEditorPane extends LineMarkedEditorPane implements MouseListener, CaretListener {
|
||||
public class DecompiledEditorPane extends LineMarkedEditorPane implements CaretListener {
|
||||
|
||||
private List<Highlighting> highlights = new ArrayList<Highlighting>();
|
||||
private List<Highlighting> traitHighlights = new ArrayList<Highlighting>();
|
||||
private List<Highlighting> methodHighlights = new ArrayList<Highlighting>();
|
||||
private List<Highlighting> classHighlights = new ArrayList<Highlighting>();
|
||||
private Highlighting currentMethodHighlight;
|
||||
private ABC abc;
|
||||
private ScriptInfo script;
|
||||
public int lastTraitIndex = 0;
|
||||
private boolean ignoreCarret = false;
|
||||
private boolean reset = false;
|
||||
private ABCPanel abcPanel;
|
||||
|
||||
public void setNoTrait() {
|
||||
Main.mainFrame.abcPanel.detailPanel.showCard(DetailPanel.UNSUPPORTED_TRAIT_CARD);
|
||||
abcPanel.detailPanel.showCard(DetailPanel.UNSUPPORTED_TRAIT_CARD);
|
||||
}
|
||||
|
||||
public void hilightOffset(long offset) {
|
||||
if (currentMethodHighlight == null) {
|
||||
return;
|
||||
}
|
||||
for (Highlighting h2 : highlights) {
|
||||
if ((h2.startPos >= currentMethodHighlight.startPos) && (h2.startPos + h2.len <= currentMethodHighlight.startPos + currentMethodHighlight.len)) {
|
||||
if (h2.offset == offset) {
|
||||
ignoreCarret = true;
|
||||
try {
|
||||
setCaretPosition(h2.startPos);
|
||||
} catch (IllegalArgumentException ie) {
|
||||
}
|
||||
getCaret().setVisible(true);
|
||||
ignoreCarret = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setClassIndex(int classIndex) {
|
||||
@@ -55,20 +81,17 @@ public class DecompiledEditorPane extends LineMarkedEditorPane implements MouseL
|
||||
if (bi == -1) {
|
||||
return false;
|
||||
}
|
||||
Main.mainFrame.abcPanel.detailPanel.showCard(DetailPanel.METHOD_TRAIT_CARD);
|
||||
if (Main.mainFrame.abcPanel.detailPanel.methodTraitPanel.methodCodePanel.sourceTextArea.bodyIndex != bi) {
|
||||
Main.mainFrame.abcPanel.detailPanel.methodTraitPanel.methodCodePanel.sourceTextArea.setBodyIndex(bi, abc);
|
||||
Main.mainFrame.abcPanel.detailPanel.methodTraitPanel.methodBodyParamsPanel.loadFromBody(abc.bodies[bi]);
|
||||
Main.mainFrame.abcPanel.detailPanel.methodTraitPanel.methodInfoPanel.load(abc.bodies[bi].method_info, abc);
|
||||
abcPanel.detailPanel.showCard(DetailPanel.METHOD_TRAIT_CARD);
|
||||
if (reset || (abcPanel.detailPanel.methodTraitPanel.methodCodePanel.getBodyIndex() != bi)) {
|
||||
abcPanel.detailPanel.methodTraitPanel.methodCodePanel.setBodyIndex(bi, abc);
|
||||
abcPanel.detailPanel.methodTraitPanel.methodBodyParamsPanel.loadFromBody(abc.bodies[bi]);
|
||||
abcPanel.detailPanel.methodTraitPanel.methodInfoPanel.load(abc.bodies[bi].method_info, abc);
|
||||
abcPanel.detailPanel.setEditMode(false);
|
||||
}
|
||||
boolean success = false;
|
||||
for (Highlighting h : highlights) {
|
||||
if ((pos >= h.startPos) && (pos < h.startPos + h.len)) {
|
||||
try {
|
||||
Main.mainFrame.abcPanel.detailPanel.methodTraitPanel.methodCodePanel.sourceTextArea.selectInstruction(abc.bodies[bi].code.adr2pos(h.offset));
|
||||
|
||||
} catch (ConvertException ex) {
|
||||
}
|
||||
abcPanel.detailPanel.methodTraitPanel.methodCodePanel.hilighOffset(h.offset);
|
||||
success = true;
|
||||
//return true;
|
||||
}
|
||||
@@ -77,51 +100,74 @@ public class DecompiledEditorPane extends LineMarkedEditorPane implements MouseL
|
||||
}
|
||||
|
||||
public void displayClass(int classIndex) {
|
||||
if (Main.mainFrame.abcPanel.navigator.getClassIndex() != classIndex) {
|
||||
Main.mainFrame.abcPanel.navigator.setClassIndex(classIndex);
|
||||
if (abcPanel.navigator.getClassIndex() != classIndex) {
|
||||
abcPanel.navigator.setClassIndex(classIndex);
|
||||
}
|
||||
}
|
||||
private int classIndex = -1;
|
||||
|
||||
public void resetEditing() {
|
||||
reset = true;
|
||||
caretUpdate(null);
|
||||
reset = false;
|
||||
}
|
||||
|
||||
public void caretUpdate(CaretEvent e) {
|
||||
getCaret().setVisible(true);
|
||||
int pos = getCaretPosition();
|
||||
|
||||
classIndex = -1;
|
||||
for (Highlighting cm : classHighlights) {
|
||||
if ((pos >= cm.startPos) && (pos < cm.startPos + cm.len)) {
|
||||
classIndex = (int) cm.offset;
|
||||
displayClass(classIndex);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (classIndex == -1) {
|
||||
setNoTrait();
|
||||
if (ignoreCarret) {
|
||||
return;
|
||||
}
|
||||
for (Highlighting tm : methodHighlights) {
|
||||
if ((pos >= tm.startPos) && (pos < tm.startPos + tm.len)) {
|
||||
displayMethod(pos, (int) tm.offset);
|
||||
return;
|
||||
}
|
||||
}
|
||||
for (Highlighting th : traitHighlights) {
|
||||
if ((pos >= th.startPos) && (pos < th.startPos + th.len)) {
|
||||
lastTraitIndex = (int) th.offset;
|
||||
Trait tr = abc.findTraitByTraitId(classIndex, (int) th.offset);
|
||||
if (tr != null) {
|
||||
if (tr instanceof TraitSlotConst) {
|
||||
Main.mainFrame.abcPanel.detailPanel.slotConstTraitPanel.load((TraitSlotConst) tr, abc);
|
||||
Main.mainFrame.abcPanel.detailPanel.showCard(DetailPanel.SLOT_CONST_TRAIT_CARD);
|
||||
return;
|
||||
}
|
||||
|
||||
getCaret().setVisible(true);
|
||||
int pos = getCaretPosition();
|
||||
abcPanel.detailPanel.methodTraitPanel.methodCodePanel.setIgnoreCarret(true);
|
||||
try {
|
||||
classIndex = -1;
|
||||
for (Highlighting cm : classHighlights) {
|
||||
if ((pos >= cm.startPos) && (pos < cm.startPos + cm.len)) {
|
||||
classIndex = (int) cm.offset;
|
||||
displayClass(classIndex);
|
||||
break;
|
||||
}
|
||||
displayMethod(pos, abc.findMethodIdByTraitId(classIndex, (int) th.offset));
|
||||
}
|
||||
|
||||
if (classIndex == -1) {
|
||||
setNoTrait();
|
||||
return;
|
||||
}
|
||||
for (Highlighting tm : methodHighlights) {
|
||||
if ((pos >= tm.startPos) && (pos < tm.startPos + tm.len)) {
|
||||
displayMethod(pos, (int) tm.offset);
|
||||
currentMethodHighlight = tm;
|
||||
|
||||
for (Highlighting th : traitHighlights) {
|
||||
if ((pos >= th.startPos) && (pos < th.startPos + th.len)) {
|
||||
lastTraitIndex = (int) th.offset;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
for (Highlighting th : traitHighlights) {
|
||||
if ((pos >= th.startPos) && (pos < th.startPos + th.len)) {
|
||||
lastTraitIndex = (int) th.offset;
|
||||
Trait tr = abc.findTraitByTraitId(classIndex, (int) th.offset);
|
||||
if (tr != null) {
|
||||
if (tr instanceof TraitSlotConst) {
|
||||
abcPanel.detailPanel.slotConstTraitPanel.load((TraitSlotConst) tr, abc);
|
||||
abcPanel.detailPanel.showCard(DetailPanel.SLOT_CONST_TRAIT_CARD);
|
||||
abcPanel.detailPanel.setEditMode(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
currentMethodHighlight = th;
|
||||
displayMethod(pos, abc.findMethodIdByTraitId(classIndex, (int) th.offset));
|
||||
return;
|
||||
}
|
||||
}
|
||||
setNoTrait();
|
||||
} finally {
|
||||
abcPanel.detailPanel.methodTraitPanel.methodCodePanel.setIgnoreCarret(false);
|
||||
}
|
||||
setNoTrait();
|
||||
}
|
||||
|
||||
private class BufferedClass {
|
||||
@@ -159,9 +205,22 @@ public class DecompiledEditorPane extends LineMarkedEditorPane implements MouseL
|
||||
if (th.offset == traitId) {
|
||||
try {
|
||||
setCaretPosition(th.startPos + th.len - 1);
|
||||
setCaretPosition(th.startPos);
|
||||
} catch (IllegalArgumentException iae) {
|
||||
}
|
||||
final int pos = th.startPos;
|
||||
new Timer().schedule(new TimerTask() {
|
||||
public void run() {
|
||||
try {
|
||||
// setCaretPosition(pos);
|
||||
} catch (IllegalArgumentException iae) {
|
||||
}
|
||||
}
|
||||
}, 100);
|
||||
invalidate();
|
||||
getParent().validate();
|
||||
setCaretPosition(pos);
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -174,12 +233,13 @@ public class DecompiledEditorPane extends LineMarkedEditorPane implements MouseL
|
||||
|
||||
setCaretPosition(0);
|
||||
}
|
||||
|
||||
|
||||
public DecompiledEditorPane() {
|
||||
addMouseListener(this);
|
||||
public DecompiledEditorPane(ABCPanel abcPanel) {
|
||||
setEditable(false);
|
||||
getCaret().setVisible(true);
|
||||
addCaretListener(this);
|
||||
this.abcPanel = abcPanel;
|
||||
}
|
||||
private List<DoABCTag> abcList;
|
||||
|
||||
@@ -208,6 +268,7 @@ public class DecompiledEditorPane extends LineMarkedEditorPane implements MouseL
|
||||
highlights = bc.highlights;
|
||||
traitHighlights = bc.traitHighlights;
|
||||
methodHighlights = bc.methodHighlights;
|
||||
classHighlights = bc.classHighlights;
|
||||
}
|
||||
setText(hilightedCode);
|
||||
this.abc = abc;
|
||||
@@ -223,24 +284,13 @@ public class DecompiledEditorPane extends LineMarkedEditorPane implements MouseL
|
||||
setNoTrait();
|
||||
}
|
||||
|
||||
public int getClassIndex() {
|
||||
return classIndex;
|
||||
}
|
||||
|
||||
public void setABC(ABC abc) {
|
||||
this.abc = abc;
|
||||
bufferedClasses.clear();
|
||||
setText("");
|
||||
}
|
||||
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
}
|
||||
|
||||
public void mousePressed(MouseEvent e) {
|
||||
}
|
||||
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
}
|
||||
|
||||
public void mouseEntered(MouseEvent e) {
|
||||
}
|
||||
|
||||
public void mouseExited(MouseEvent e) {
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user