AS3 Two sided Highlighting, Edit/Cancel button

This commit is contained in:
Jindra Petk
2013-01-26 13:11:41 +01:00
parent 6fa4320d76
commit d2e5073ff2
15 changed files with 336 additions and 143 deletions

View File

@@ -55,6 +55,7 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.swing.text.Highlighter;
public class AVM2Code {
@@ -728,7 +729,7 @@ public class AVM2Code {
ret += "exceptiontarget " + e + ":";
}
}
ret += ins.toStringNoAddress(constants, new ArrayList<String>()) + "\n";
ret += Highlighting.hilighOffset("", ofs) + ins.toStringNoAddress(constants, new ArrayList<String>()) + "\n";
ofs += ins.getBytes().length;
}

View File

@@ -50,7 +50,7 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener {
public JSplitPane splitPaneTreeNavVSDecompiledDetail;
private JTable constantTable;
public JComboBox constantTypeList;
public JLabel asmLabel = new JLabel("P-code source (editable)");
public JLabel asmLabel = new JLabel("P-code source");
public JLabel decLabel = new JLabel("ActionScript source");
public DetailPanel detailPanel;
public JTextField filterField = new JTextField("");
@@ -183,11 +183,10 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener {
decompiledTextArea = new DecompiledEditorPane();
decompiledScrollPane = new JScrollPane(decompiledTextArea);
detailPanel = new DetailPanel();
decompiledTextArea = new DecompiledEditorPane(this);
decompiledScrollPane = new JScrollPane(decompiledTextArea);
detailPanel = new DetailPanel(this);
JPanel panB = new JPanel();
panB.setLayout(new BorderLayout());
panB.add(decompiledScrollPane, BorderLayout.CENTER);
@@ -204,7 +203,7 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener {
pan2.setLayout(new BorderLayout());
pan2.add((abcComboBox = new JComboBox(new ABCComboBoxModel(list))), BorderLayout.NORTH);
navigator = new TraitsList();
navigator = new TraitsList(this);
navigator.setABC(list, abc);
@@ -244,7 +243,7 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener {
JPanel treePanel = new JPanel();
treePanel.setLayout(new BorderLayout());
treePanel.add(new JScrollPane(classTree = new ClassesListTree(list)), BorderLayout.CENTER);
treePanel.add(new JScrollPane(classTree = new ClassesListTree(list,this)), BorderLayout.CENTER);
JPanel searchPanel = new JPanel();
searchPanel.setLayout(new BorderLayout());
searchPanel.add(filterField, BorderLayout.CENTER);
@@ -290,7 +289,7 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener {
constantTable.setAutoCreateRowSorter(true);
final List<DoABCTag> inlist = list;
final ABCPanel t=this;
constantTable.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
@@ -302,7 +301,7 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener {
}
int multinameIndex = constantTable.convertRowIndexToModel(rowIndex);
if (multinameIndex > 0) {
UsageFrame usageFrame = new UsageFrame(inlist, abc, multinameIndex);
UsageFrame usageFrame = new UsageFrame(inlist, abc, multinameIndex,t);
usageFrame.setVisible(true);
}
}

View File

@@ -22,17 +22,48 @@ import com.jpexs.asdec.abc.avm2.ConstantPool;
import com.jpexs.asdec.abc.avm2.flowgraph.Graph;
import com.jpexs.asdec.abc.avm2.parser.ASM3Parser;
import com.jpexs.asdec.abc.avm2.parser.ParseException;
import com.jpexs.asdec.helpers.Highlighting;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import javax.swing.JOptionPane;
import javax.swing.event.CaretEvent;
import javax.swing.event.CaretListener;
public class ASMSourceEditorPane extends LineMarkedEditorPane {
public class ASMSourceEditorPane extends LineMarkedEditorPane implements CaretListener {
public ABC abc;
public int bodyIndex = -1;
private List<Highlighting> disassembledHilights = new ArrayList<Highlighting>();
private DecompiledEditorPane decompiledEditor;
private boolean ignoreCarret = false;
public ASMSourceEditorPane() {
public void setIgnoreCarret(boolean ignoreCarret) {
this.ignoreCarret = ignoreCarret;
}
public ASMSourceEditorPane(DecompiledEditorPane decompiledEditor) {
this.decompiledEditor = decompiledEditor;
addCaretListener(this);
}
public void hilighOffset(long offset) {
if(isEditable()){
return;
}
for (Highlighting h2 : disassembledHilights) {
if (h2.offset == offset) {
ignoreCarret = true;
setCaretPosition(h2.startPos);
getCaret().setVisible(true);
ignoreCarret = false;
break;
}
}
}
public void setBodyIndex(int bodyIndex, ABC abc) {
@@ -69,6 +100,12 @@ public class ASMSourceEditorPane extends LineMarkedEditorPane {
return true;
}
@Override
public void setText(String t) {
disassembledHilights = Highlighting.getInstrHighlights(t);
super.setText(Highlighting.stripHilights(t));
}
public void verify(ConstantPool constants, ABC abc) {
try {
AVM2Code acode = ASM3Parser.parse(new ByteArrayInputStream(getText().getBytes()), constants, new DialogMissingSymbolHandler(), abc.bodies[bodyIndex]);
@@ -140,4 +177,24 @@ public class ASMSourceEditorPane extends LineMarkedEditorPane {
select(lineStart, lineEnd);
requestFocus();
}
@Override
public void caretUpdate(CaretEvent e) {
if(isEditable()){
return;
}
if (ignoreCarret) {
return;
}
getCaret().setVisible(true);
int pos = getCaretPosition();
Highlighting lastH = new Highlighting(0, 0, 0);
for (Highlighting h : disassembledHilights) {
if (pos < h.startPos) {
break;
}
lastH = h;
}
decompiledEditor.hilightOffset(lastH.offset);
}
}

View File

@@ -35,6 +35,7 @@ public class ClassesListTree extends JTree implements TreeSelectionListener {
private List<DoABCTag> abcList;
private HashMap<String, TreeLeafScript> treeList;
private ABCPanel abcPanel;
public void selectClass(int classIndex) {
ClassesListTreeModel model = (ClassesListTreeModel) getModel();
@@ -44,9 +45,10 @@ public class ClassesListTree extends JTree implements TreeSelectionListener {
scrollPathToVisible(treePath);
}
public ClassesListTree(List<DoABCTag> list) {
public ClassesListTree(List<DoABCTag> list,ABCPanel abcPanel) {
this.abcList = list;
this.treeList = getTreeList(list);
this.abcPanel=abcPanel;
setModel(new ClassesListTreeModel(this.treeList));
addTreeSelectionListener(this);
DefaultTreeCellRenderer treeRenderer = new DefaultTreeCellRenderer();
@@ -138,12 +140,13 @@ public class ClassesListTree extends JTree implements TreeSelectionListener {
break;
}
}
Main.mainFrame.abcPanel.navigator.setABC(abcList, scriptLeaf.abc);
Main.mainFrame.abcPanel.navigator.setClassIndex(classIndex);
Main.mainFrame.abcPanel.setAbc(scriptLeaf.abc);
Main.mainFrame.abcPanel.decompiledTextArea.setScript(scriptLeaf.abc.script_info[scriptLeaf.scriptIndex], scriptLeaf.abc, abcList);
Main.mainFrame.abcPanel.decompiledTextArea.setClassIndex(classIndex);
Main.mainFrame.abcPanel.detailPanel.methodTraitPanel.methodCodePanel.sourceTextArea.setText("");
abcPanel.navigator.setABC(abcList, scriptLeaf.abc);
abcPanel.navigator.setClassIndex(classIndex);
abcPanel.setAbc(scriptLeaf.abc);
abcPanel.decompiledTextArea.setScript(scriptLeaf.abc.script_info[scriptLeaf.scriptIndex], scriptLeaf.abc, abcList);
abcPanel.decompiledTextArea.setClassIndex(classIndex);
abcPanel.decompiledTextArea.setNoTrait();
abcPanel.detailPanel.methodTraitPanel.methodCodePanel.setCode("");
Main.stopWork();
}
}).start();

View File

@@ -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) {
}
}

View File

@@ -39,16 +39,22 @@ public class DetailPanel extends JPanel implements ActionListener {
public static final String UNSUPPORTED_TRAIT_CARD = "-";
public static final String SLOT_CONST_TRAIT_CARD = "Slot/Const Trait";
private JPanel innerPanel;
public JButton saveButton;
public JButton saveButton = new JButton("Save");
public JButton editButton = new JButton("Edit");
public JButton cancelButton = new JButton("Cancel");
private HashMap<String, JComponent> cardMap = new HashMap<String, JComponent>();
private String selectedCard;
private JLabel selectedLabel;
private boolean editMode = false;
private JPanel buttonsPanel;
private ABCPanel abcPanel;
public DetailPanel() {
public DetailPanel(ABCPanel abcPanel) {
this.abcPanel=abcPanel;
innerPanel = new JPanel();
CardLayout layout = new CardLayout();
innerPanel.setLayout(layout);
methodTraitPanel = new MethodTraitDetailPanel();
methodTraitPanel = new MethodTraitDetailPanel(abcPanel);
cardMap.put(METHOD_TRAIT_CARD, methodTraitPanel);
unsupportedTraitPanel = new JPanel(new BorderLayout());
@@ -67,17 +73,22 @@ public class DetailPanel extends JPanel implements ActionListener {
setLayout(new BorderLayout());
add(innerPanel, BorderLayout.CENTER);
JPanel buttonsPanel = new JPanel();
buttonsPanel = new JPanel();
buttonsPanel.setLayout(new FlowLayout());
saveButton = new JButton("Save trait");
saveButton.setActionCommand("SAVEDETAIL");
saveButton.addActionListener(this);
editButton.setActionCommand("EDITDETAIL");
editButton.addActionListener(this);
cancelButton.setActionCommand("CANCELDETAIL");
cancelButton.addActionListener(this);
buttonsPanel.setBorder(new BevelBorder(BevelBorder.RAISED));
buttonsPanel.add(editButton);
buttonsPanel.add(saveButton);
buttonsPanel.add(cancelButton);
add(buttonsPanel, BorderLayout.SOUTH);
selectedCard = UNSUPPORTED_TRAIT_CARD;
layout.show(innerPanel, UNSUPPORTED_TRAIT_CARD);
saveButton.setVisible(false);
buttonsPanel.setVisible(false);
selectedLabel = new JLabel("");
selectedLabel.setText(selectedCard);
selectedLabel.setBorder(new BevelBorder(BevelBorder.RAISED));
@@ -85,21 +96,40 @@ public class DetailPanel extends JPanel implements ActionListener {
add(selectedLabel, BorderLayout.NORTH);
}
public void setEditMode(boolean val) {
slotConstTraitPanel.setEditMode(val);
methodTraitPanel.setEditMode(val);
saveButton.setVisible(val);
editButton.setVisible(!val);
cancelButton.setVisible(val);
editMode = val;
}
public void showCard(String name) {
CardLayout layout = (CardLayout) innerPanel.getLayout();
layout.show(innerPanel, name);
saveButton.setVisible(cardMap.get(name) instanceof TraitDetail);
boolean b = cardMap.get(name) instanceof TraitDetail;
buttonsPanel.setVisible(b);
selectedCard = name;
selectedLabel.setText(selectedCard);
selectedLabel.setText(selectedCard);
}
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand().equals("EDITDETAIL")) {
setEditMode(true);
}
if (e.getActionCommand().equals("CANCELDETAIL")) {
setEditMode(false);
abcPanel.decompiledTextArea.resetEditing();
}
if (e.getActionCommand().equals("SAVEDETAIL")) {
if (cardMap.get(selectedCard) instanceof TraitDetail) {
if (((TraitDetail) cardMap.get(selectedCard)).save()) {
int lasttrait = Main.mainFrame.abcPanel.decompiledTextArea.lastTraitIndex;
Main.mainFrame.abcPanel.decompiledTextArea.reloadClass();
Main.mainFrame.abcPanel.decompiledTextArea.gotoTrait(lasttrait);
int lasttrait = abcPanel.decompiledTextArea.lastTraitIndex;
int lastclass = abcPanel.decompiledTextArea.getClassIndex();
abcPanel.decompiledTextArea.reloadClass();
abcPanel.decompiledTextArea.setClassIndex(lastclass);
abcPanel.decompiledTextArea.gotoTrait(lasttrait);
JOptionPane.showMessageDialog(this, "Trait Successfully saved");
}
}

View File

@@ -42,9 +42,10 @@ public class MethodBodyParamsPanel extends JPanel implements ChangeListener {
public MethodBody body;
public JCheckBox autoFillCheckBox = new JCheckBox("Auto fill on code save (GLOBAL SETTING)");
public JLabel experimentalLabel = new JLabel("...EXPERIMENTAL");
public MethodBodyParamsPanel() {
private ABCPanel abcPanel;
public MethodBodyParamsPanel(ABCPanel abcPanel) {
setLayout(null);
this.abcPanel=abcPanel;
maxStackLabel.setBounds(10, 10, 150, 25);
maxStackField.setBounds(10 + 150 + 10, 10, 75, 25);
@@ -100,7 +101,7 @@ public class MethodBodyParamsPanel extends JPanel implements ChangeListener {
body.max_regs = Integer.parseInt(localCountField.getText());
body.max_scope_depth = Integer.parseInt(maxScopeDepthField.getText());
} else {
if (!body.autoFillStats(Main.mainFrame.abcPanel.abc)) {
if (!body.autoFillStats(abcPanel.abc)) {
JOptionPane.showMessageDialog(null, "Cannot get code stats for automatic body params.\r\nUncheck autofill to avoid this message.", "Warning", JOptionPane.WARNING_MESSAGE);
}
}
@@ -122,4 +123,12 @@ public class MethodBodyParamsPanel extends JPanel implements ChangeListener {
}
}
}
public void setEditMode(boolean val) {
maxStackField.setEditable(val);
localCountField.setEditable(val);
initScopeDepthField.setEditable(val);
maxScopeDepthField.setEditable(val);
autoFillCheckBox.setEnabled(val);
}
}

View File

@@ -17,6 +17,8 @@
package com.jpexs.asdec.abc.gui;
import com.jpexs.asdec.Main;
import com.jpexs.asdec.abc.ABC;
import com.jpexs.asdec.abc.avm2.ConstantPool;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
@@ -31,11 +33,35 @@ import javax.swing.JScrollPane;
*/
public class MethodCodePanel extends JPanel implements ActionListener {
public ASMSourceEditorPane sourceTextArea;
private ASMSourceEditorPane sourceTextArea;
public JPanel buttonsPanel;
public void setIgnoreCarret(boolean ignoreCarret) {
sourceTextArea.setIgnoreCarret(ignoreCarret);
}
public MethodCodePanel() {
sourceTextArea = new ASMSourceEditorPane();
public void hilighOffset(long offset) {
sourceTextArea.hilighOffset(offset);
}
public void setBodyIndex(int bodyIndex, ABC abc) {
sourceTextArea.setBodyIndex(bodyIndex, abc);
}
public int getBodyIndex() {
return sourceTextArea.bodyIndex;
}
public void setCode(String text) {
sourceTextArea.setText(text);
}
public boolean save(ConstantPool constants) {
return sourceTextArea.save(constants);
}
public MethodCodePanel(DecompiledEditorPane decompiledEditor) {
sourceTextArea = new ASMSourceEditorPane(decompiledEditor);
setLayout(new BorderLayout());
add(new JScrollPane(sourceTextArea), BorderLayout.CENTER);
@@ -77,4 +103,9 @@ public class MethodCodePanel extends JPanel implements ActionListener {
sourceTextArea.verify(Main.mainFrame.abcPanel.abc.constants, Main.mainFrame.abcPanel.abc);
}
}
public void setEditMode(boolean val) {
sourceTextArea.setEditable(val);
sourceTextArea.getCaret().setVisible(true);
}
}

View File

@@ -114,4 +114,9 @@ public class MethodInfoPanel extends JPanel {
}
return true;
}
public void setEditMode(boolean val) {
returnTypeEditor.setEditable(val);
paramEditor.setEditable(val);
}
}

View File

@@ -29,10 +29,12 @@ public class MethodTraitDetailPanel extends JTabbedPane implements TraitDetail {
public MethodCodePanel methodCodePanel;
public MethodBodyParamsPanel methodBodyParamsPanel;
public MethodInfoPanel methodInfoPanel;
public ABCPanel abcPanel;
public MethodTraitDetailPanel() {
methodCodePanel = new MethodCodePanel();
methodBodyParamsPanel = new MethodBodyParamsPanel();
public MethodTraitDetailPanel(ABCPanel abcPanel) {
this.abcPanel=abcPanel;
methodCodePanel = new MethodCodePanel(abcPanel.decompiledTextArea);
methodBodyParamsPanel = new MethodBodyParamsPanel(abcPanel);
methodInfoPanel = new MethodInfoPanel();
addTab("MethodInfo", methodInfoPanel);
addTab("MethodBody Code", methodCodePanel);
@@ -44,7 +46,7 @@ public class MethodTraitDetailPanel extends JTabbedPane implements TraitDetail {
if (!methodInfoPanel.save()) {
return false;
}
if (!methodCodePanel.sourceTextArea.save(Main.mainFrame.abcPanel.abc.constants)) {
if (!methodCodePanel.save(abcPanel.abc.constants)) {
return false;
}
if (!methodBodyParamsPanel.save()) {
@@ -53,4 +55,11 @@ public class MethodTraitDetailPanel extends JTabbedPane implements TraitDetail {
return true;
}
@Override
public void setEditMode(boolean val) {
methodCodePanel.setEditMode(val);
methodBodyParamsPanel.setEditMode(val);
methodInfoPanel.setEditMode(val);
}
}

View File

@@ -78,4 +78,9 @@ public class SlotConstTraitDetailPanel extends JPanel implements TraitDetail {
}
return true;
}
@Override
public void setEditMode(boolean val) {
slotConstEditor.setEditable(val);
}
}

View File

@@ -22,5 +22,7 @@ package com.jpexs.asdec.abc.gui;
*/
public interface TraitDetail {
public void setEditMode(boolean val);
public boolean save();
}

View File

@@ -30,13 +30,14 @@ public class TraitsList extends JList implements ListSelectionListener {
ABC abc;
List<DoABCTag> abcTags;
int classIndex = -1;
private ABCPanel abcPanel;
public int getClassIndex() {
return classIndex;
}
public TraitsList() {
public TraitsList(ABCPanel abcPanel) {
addListSelectionListener(this);
this.abcPanel=abcPanel;
setCellRenderer(new IconListRenderer());
}
@@ -62,7 +63,7 @@ public class TraitsList extends JList implements ListSelectionListener {
int index = getSelectedIndex();
Main.mainFrame.abcPanel.decompiledTextArea.gotoTrait(index);
abcPanel.decompiledTextArea.gotoTrait(index);
}
}

View File

@@ -45,8 +45,10 @@ public class UsageFrame extends JFrame implements ActionListener, MouseListener
private JList usageList;
private UsageListModel usageListModel;
private ABC abc;
private ABCPanel abcPanel;
public UsageFrame(List<DoABCTag> abcTags, ABC abc, int multinameIndex) {
public UsageFrame(List<DoABCTag> abcTags, ABC abc, int multinameIndex,ABCPanel abcPanel) {
this.abcPanel=abcPanel;
List<MultinameUsage> usages = abc.findMultinameUsage(multinameIndex);
this.abc = abc;
usageListModel = new UsageListModel(abcTags, abc);
@@ -79,7 +81,7 @@ public class UsageFrame extends JFrame implements ActionListener, MouseListener
MultinameUsage usage = usageListModel.getUsage(usageList.getSelectedIndex());
if (usage instanceof InsideClassMultinameUsage) {
InsideClassMultinameUsage icu = (InsideClassMultinameUsage) usage;
Main.mainFrame.abcPanel.classTree.selectClass(icu.classIndex);
abcPanel.classTree.selectClass(icu.classIndex);
try {
Thread.sleep(100);
} catch (InterruptedException ex) {
@@ -101,7 +103,7 @@ public class UsageFrame extends JFrame implements ActionListener, MouseListener
traitIndex = abc.class_info[mmu.classIndex].static_traits.traits.length + abc.instance_info[mmu.classIndex].instance_traits.traits.length + (mmu.isStatic ? 1 : 0);
}
}
Main.mainFrame.abcPanel.decompiledTextArea.gotoTrait(traitIndex);
abcPanel.decompiledTextArea.gotoTrait(traitIndex);
}
}
}

View File

@@ -60,10 +60,10 @@ public class ActionPanel extends JPanel implements TreeSelectionListener, Action
public JLabel decLabel = new JLabel("ActionScript source");
public List<Highlighting> decompiledHilights = new ArrayList<Highlighting>();
public List<Highlighting> disassembledHilights = new ArrayList<Highlighting>();
private String lastDisasm = "";
private boolean ignoreCarret = false;
private boolean editMode = false;
private String lastDisasm="";
private boolean ignoreCarret=false;
private boolean editMode=false;
public ActionPanel(List<Tag> list) {
this.list = list;
DefaultSyntaxKit.initKit();
@@ -90,7 +90,7 @@ public class ActionPanel extends JPanel implements TreeSelectionListener, Action
JPanel buttonsPan = new JPanel();
buttonsPan.setLayout(new FlowLayout());
buttonsPan.add(editButton);
buttonsPan.add(saveButton);
buttonsPan.add(saveButton);
buttonsPan.add(cancelButton);
//buttonsPan.add(saveHexButton);
//buttonsPan.add(loadHexButton);
@@ -108,7 +108,7 @@ public class ActionPanel extends JPanel implements TreeSelectionListener, Action
cancelButton.setActionCommand("CANCELACTION");
saveButton.setVisible(false);
cancelButton.setVisible(false);
JPanel panA = new JPanel();
panA.setLayout(new BorderLayout());
@@ -131,7 +131,7 @@ public class ActionPanel extends JPanel implements TreeSelectionListener, Action
editor.addCaretListener(new CaretListener() {
@Override
public void caretUpdate(CaretEvent e) {
if(ignoreCarret){
if (ignoreCarret) {
return;
}
editor.getCaret().setVisible(true);
@@ -139,25 +139,16 @@ public class ActionPanel extends JPanel implements TreeSelectionListener, Action
Highlighting lastH = new Highlighting(0, 0, 0);
for (Highlighting h : disassembledHilights) {
if (pos < h.startPos) {
for (Highlighting h2 : decompiledHilights) {
if (h2.offset == lastH.offset) {
ignoreCarret=true;
decompiledEditor.setCaretPosition(h2.startPos);
decompiledEditor.getCaret().setVisible(true);
ignoreCarret=false;
break;
}
}
break;
}
lastH = h;
}
for (Highlighting h2 : decompiledHilights) {
if (h2.offset == lastH.offset) {
ignoreCarret=true;
ignoreCarret = true;
decompiledEditor.setCaretPosition(h2.startPos);
decompiledEditor.getCaret().setVisible(true);
ignoreCarret=false;
ignoreCarret = false;
break;
}
}
@@ -166,10 +157,10 @@ public class ActionPanel extends JPanel implements TreeSelectionListener, Action
decompiledEditor.addCaretListener(new CaretListener() {
@Override
public void caretUpdate(CaretEvent e) {
if(ignoreCarret){
if (ignoreCarret) {
return;
}
if(editMode){
if (editMode) {
return;
}
decompiledEditor.getCaret().setVisible(true);
@@ -178,10 +169,10 @@ public class ActionPanel extends JPanel implements TreeSelectionListener, Action
if ((pos >= h.startPos) && (pos < h.startPos + h.len)) {
for (Highlighting h2 : disassembledHilights) {
if (h2.offset == h.offset) {
ignoreCarret=true;
ignoreCarret = true;
editor.setCaretPosition(h2.startPos);
editor.getCaret().setVisible(true);
ignoreCarret=false;
ignoreCarret = false;
break;
}
}
@@ -211,8 +202,8 @@ public class ActionPanel extends JPanel implements TreeSelectionListener, Action
@Override
public void run() {
lastDisasm = asm.getASMSource(SWF.DEFAULT_VERSION);
disassembledHilights = Highlighting.getInstrHighlights(lastDisasm);
lastDisasm=Highlighting.stripHilights(lastDisasm);
disassembledHilights = Highlighting.getInstrHighlights(lastDisasm);
lastDisasm = Highlighting.stripHilights(lastDisasm);
editor.setText(lastDisasm);
if (Main.DO_DECOMPILE) {
List<com.jpexs.asdec.action.Action> as = asm.getActions(SWF.DEFAULT_VERSION);
@@ -249,32 +240,30 @@ public class ActionPanel extends JPanel implements TreeSelectionListener, Action
return ret;
}
public void setEditMode(boolean val){
if(val){
public void setEditMode(boolean val) {
if (val) {
editor.setEditable(true);
saveButton.setVisible(true);
editButton.setVisible(false);
cancelButton.setVisible(true);
editor.getCaret().setVisible(true);
}else{
} else {
editor.setEditable(false);
saveButton.setVisible(false);
editButton.setVisible(true);
cancelButton.setVisible(false);
editor.getCaret().setVisible(true);
}
editMode=val;
editMode = val;
}
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand().equals("EDITACTION")) {
setEditMode(true);
}else
if (e.getActionCommand().equals("CANCELACTION")) {
} else if (e.getActionCommand().equals("CANCELACTION")) {
setEditMode(false);
editor.setText(lastDisasm);
}else
if (e.getActionCommand().equals("SAVEACTION")) {
} else if (e.getActionCommand().equals("SAVEACTION")) {
TagNode ti = (TagNode) tagTree.getLastSelectedPathComponent();
if (ti.tag instanceof ASMSource) {
ASMSource dat = (ASMSource) ti.tag;