AS3 Two sided Highlighting, Edit/Cancel button

This commit is contained in:
Jindra Pet��k
2013-01-26 13:11:41 +01:00
parent 6fa4320d76
commit d2e5073ff2
15 changed files with 336 additions and 143 deletions
@@ -55,6 +55,7 @@ import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import javax.swing.text.Highlighter;
public class AVM2Code { public class AVM2Code {
@@ -728,7 +729,7 @@ public class AVM2Code {
ret += "exceptiontarget " + e + ":"; 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; ofs += ins.getBytes().length;
} }
@@ -50,7 +50,7 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener {
public JSplitPane splitPaneTreeNavVSDecompiledDetail; public JSplitPane splitPaneTreeNavVSDecompiledDetail;
private JTable constantTable; private JTable constantTable;
public JComboBox constantTypeList; 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 JLabel decLabel = new JLabel("ActionScript source");
public DetailPanel detailPanel; public DetailPanel detailPanel;
public JTextField filterField = new JTextField(""); public JTextField filterField = new JTextField("");
@@ -183,11 +183,10 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener {
decompiledTextArea = new DecompiledEditorPane();
decompiledTextArea = new DecompiledEditorPane(this);
decompiledScrollPane = new JScrollPane(decompiledTextArea); decompiledScrollPane = new JScrollPane(decompiledTextArea);
detailPanel = new DetailPanel(this);
detailPanel = new DetailPanel();
JPanel panB = new JPanel(); JPanel panB = new JPanel();
panB.setLayout(new BorderLayout()); panB.setLayout(new BorderLayout());
panB.add(decompiledScrollPane, BorderLayout.CENTER); panB.add(decompiledScrollPane, BorderLayout.CENTER);
@@ -204,7 +203,7 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener {
pan2.setLayout(new BorderLayout()); pan2.setLayout(new BorderLayout());
pan2.add((abcComboBox = new JComboBox(new ABCComboBoxModel(list))), BorderLayout.NORTH); pan2.add((abcComboBox = new JComboBox(new ABCComboBoxModel(list))), BorderLayout.NORTH);
navigator = new TraitsList(); navigator = new TraitsList(this);
navigator.setABC(list, abc); navigator.setABC(list, abc);
@@ -244,7 +243,7 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener {
JPanel treePanel = new JPanel(); JPanel treePanel = new JPanel();
treePanel.setLayout(new BorderLayout()); 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(); JPanel searchPanel = new JPanel();
searchPanel.setLayout(new BorderLayout()); searchPanel.setLayout(new BorderLayout());
searchPanel.add(filterField, BorderLayout.CENTER); searchPanel.add(filterField, BorderLayout.CENTER);
@@ -290,7 +289,7 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener {
constantTable.setAutoCreateRowSorter(true); constantTable.setAutoCreateRowSorter(true);
final List<DoABCTag> inlist = list; final List<DoABCTag> inlist = list;
final ABCPanel t=this;
constantTable.addMouseListener(new MouseAdapter() { constantTable.addMouseListener(new MouseAdapter() {
@Override @Override
public void mouseClicked(MouseEvent e) { public void mouseClicked(MouseEvent e) {
@@ -302,7 +301,7 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener {
} }
int multinameIndex = constantTable.convertRowIndexToModel(rowIndex); int multinameIndex = constantTable.convertRowIndexToModel(rowIndex);
if (multinameIndex > 0) { if (multinameIndex > 0) {
UsageFrame usageFrame = new UsageFrame(inlist, abc, multinameIndex); UsageFrame usageFrame = new UsageFrame(inlist, abc, multinameIndex,t);
usageFrame.setVisible(true); usageFrame.setVisible(true);
} }
} }
@@ -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.flowgraph.Graph;
import com.jpexs.asdec.abc.avm2.parser.ASM3Parser; import com.jpexs.asdec.abc.avm2.parser.ASM3Parser;
import com.jpexs.asdec.abc.avm2.parser.ParseException; import com.jpexs.asdec.abc.avm2.parser.ParseException;
import com.jpexs.asdec.helpers.Highlighting;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import javax.swing.JOptionPane; 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 ABC abc;
public int bodyIndex = -1; 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) { public void setBodyIndex(int bodyIndex, ABC abc) {
@@ -69,6 +100,12 @@ public class ASMSourceEditorPane extends LineMarkedEditorPane {
return true; return true;
} }
@Override
public void setText(String t) {
disassembledHilights = Highlighting.getInstrHighlights(t);
super.setText(Highlighting.stripHilights(t));
}
public void verify(ConstantPool constants, ABC abc) { public void verify(ConstantPool constants, ABC abc) {
try { try {
AVM2Code acode = ASM3Parser.parse(new ByteArrayInputStream(getText().getBytes()), constants, new DialogMissingSymbolHandler(), abc.bodies[bodyIndex]); 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); select(lineStart, lineEnd);
requestFocus(); 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);
}
} }
@@ -35,6 +35,7 @@ public class ClassesListTree extends JTree implements TreeSelectionListener {
private List<DoABCTag> abcList; private List<DoABCTag> abcList;
private HashMap<String, TreeLeafScript> treeList; private HashMap<String, TreeLeafScript> treeList;
private ABCPanel abcPanel;
public void selectClass(int classIndex) { public void selectClass(int classIndex) {
ClassesListTreeModel model = (ClassesListTreeModel) getModel(); ClassesListTreeModel model = (ClassesListTreeModel) getModel();
@@ -44,9 +45,10 @@ public class ClassesListTree extends JTree implements TreeSelectionListener {
scrollPathToVisible(treePath); scrollPathToVisible(treePath);
} }
public ClassesListTree(List<DoABCTag> list) { public ClassesListTree(List<DoABCTag> list,ABCPanel abcPanel) {
this.abcList = list; this.abcList = list;
this.treeList = getTreeList(list); this.treeList = getTreeList(list);
this.abcPanel=abcPanel;
setModel(new ClassesListTreeModel(this.treeList)); setModel(new ClassesListTreeModel(this.treeList));
addTreeSelectionListener(this); addTreeSelectionListener(this);
DefaultTreeCellRenderer treeRenderer = new DefaultTreeCellRenderer(); DefaultTreeCellRenderer treeRenderer = new DefaultTreeCellRenderer();
@@ -138,12 +140,13 @@ public class ClassesListTree extends JTree implements TreeSelectionListener {
break; break;
} }
} }
Main.mainFrame.abcPanel.navigator.setABC(abcList, scriptLeaf.abc); abcPanel.navigator.setABC(abcList, scriptLeaf.abc);
Main.mainFrame.abcPanel.navigator.setClassIndex(classIndex); abcPanel.navigator.setClassIndex(classIndex);
Main.mainFrame.abcPanel.setAbc(scriptLeaf.abc); abcPanel.setAbc(scriptLeaf.abc);
Main.mainFrame.abcPanel.decompiledTextArea.setScript(scriptLeaf.abc.script_info[scriptLeaf.scriptIndex], scriptLeaf.abc, abcList); abcPanel.decompiledTextArea.setScript(scriptLeaf.abc.script_info[scriptLeaf.scriptIndex], scriptLeaf.abc, abcList);
Main.mainFrame.abcPanel.decompiledTextArea.setClassIndex(classIndex); abcPanel.decompiledTextArea.setClassIndex(classIndex);
Main.mainFrame.abcPanel.detailPanel.methodTraitPanel.methodCodePanel.sourceTextArea.setText(""); abcPanel.decompiledTextArea.setNoTrait();
abcPanel.detailPanel.methodTraitPanel.methodCodePanel.setCode("");
Main.stopWork(); Main.stopWork();
} }
}).start(); }).start();
@@ -29,21 +29,47 @@ import java.awt.event.MouseListener;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
import javax.swing.event.CaretEvent; import javax.swing.event.CaretEvent;
import javax.swing.event.CaretListener; 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> highlights = new ArrayList<Highlighting>();
private List<Highlighting> traitHighlights = new ArrayList<Highlighting>(); private List<Highlighting> traitHighlights = new ArrayList<Highlighting>();
private List<Highlighting> methodHighlights = new ArrayList<Highlighting>(); private List<Highlighting> methodHighlights = new ArrayList<Highlighting>();
private List<Highlighting> classHighlights = new ArrayList<Highlighting>(); private List<Highlighting> classHighlights = new ArrayList<Highlighting>();
private Highlighting currentMethodHighlight;
private ABC abc; private ABC abc;
private ScriptInfo script; private ScriptInfo script;
public int lastTraitIndex = 0; public int lastTraitIndex = 0;
private boolean ignoreCarret = false;
private boolean reset = false;
private ABCPanel abcPanel;
public void setNoTrait() { 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) { public void setClassIndex(int classIndex) {
@@ -55,20 +81,17 @@ public class DecompiledEditorPane extends LineMarkedEditorPane implements MouseL
if (bi == -1) { if (bi == -1) {
return false; return false;
} }
Main.mainFrame.abcPanel.detailPanel.showCard(DetailPanel.METHOD_TRAIT_CARD); abcPanel.detailPanel.showCard(DetailPanel.METHOD_TRAIT_CARD);
if (Main.mainFrame.abcPanel.detailPanel.methodTraitPanel.methodCodePanel.sourceTextArea.bodyIndex != bi) { if (reset || (abcPanel.detailPanel.methodTraitPanel.methodCodePanel.getBodyIndex() != bi)) {
Main.mainFrame.abcPanel.detailPanel.methodTraitPanel.methodCodePanel.sourceTextArea.setBodyIndex(bi, abc); abcPanel.detailPanel.methodTraitPanel.methodCodePanel.setBodyIndex(bi, abc);
Main.mainFrame.abcPanel.detailPanel.methodTraitPanel.methodBodyParamsPanel.loadFromBody(abc.bodies[bi]); abcPanel.detailPanel.methodTraitPanel.methodBodyParamsPanel.loadFromBody(abc.bodies[bi]);
Main.mainFrame.abcPanel.detailPanel.methodTraitPanel.methodInfoPanel.load(abc.bodies[bi].method_info, abc); abcPanel.detailPanel.methodTraitPanel.methodInfoPanel.load(abc.bodies[bi].method_info, abc);
abcPanel.detailPanel.setEditMode(false);
} }
boolean success = false; boolean success = false;
for (Highlighting h : highlights) { for (Highlighting h : highlights) {
if ((pos >= h.startPos) && (pos < h.startPos + h.len)) { if ((pos >= h.startPos) && (pos < h.startPos + h.len)) {
try { abcPanel.detailPanel.methodTraitPanel.methodCodePanel.hilighOffset(h.offset);
Main.mainFrame.abcPanel.detailPanel.methodTraitPanel.methodCodePanel.sourceTextArea.selectInstruction(abc.bodies[bi].code.adr2pos(h.offset));
} catch (ConvertException ex) {
}
success = true; success = true;
//return true; //return true;
} }
@@ -77,51 +100,74 @@ public class DecompiledEditorPane extends LineMarkedEditorPane implements MouseL
} }
public void displayClass(int classIndex) { public void displayClass(int classIndex) {
if (Main.mainFrame.abcPanel.navigator.getClassIndex() != classIndex) { if (abcPanel.navigator.getClassIndex() != classIndex) {
Main.mainFrame.abcPanel.navigator.setClassIndex(classIndex); abcPanel.navigator.setClassIndex(classIndex);
} }
} }
private int classIndex = -1; private int classIndex = -1;
public void resetEditing() {
reset = true;
caretUpdate(null);
reset = false;
}
public void caretUpdate(CaretEvent e) { public void caretUpdate(CaretEvent e) {
getCaret().setVisible(true); if (ignoreCarret) {
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();
return; return;
} }
for (Highlighting tm : methodHighlights) {
if ((pos >= tm.startPos) && (pos < tm.startPos + tm.len)) { getCaret().setVisible(true);
displayMethod(pos, (int) tm.offset); int pos = getCaretPosition();
return; abcPanel.detailPanel.methodTraitPanel.methodCodePanel.setIgnoreCarret(true);
} try {
} classIndex = -1;
for (Highlighting th : traitHighlights) { for (Highlighting cm : classHighlights) {
if ((pos >= th.startPos) && (pos < th.startPos + th.len)) { if ((pos >= cm.startPos) && (pos < cm.startPos + cm.len)) {
lastTraitIndex = (int) th.offset; classIndex = (int) cm.offset;
Trait tr = abc.findTraitByTraitId(classIndex, (int) th.offset); displayClass(classIndex);
if (tr != null) { break;
if (tr instanceof TraitSlotConst) {
Main.mainFrame.abcPanel.detailPanel.slotConstTraitPanel.load((TraitSlotConst) tr, abc);
Main.mainFrame.abcPanel.detailPanel.showCard(DetailPanel.SLOT_CONST_TRAIT_CARD);
return;
}
} }
displayMethod(pos, abc.findMethodIdByTraitId(classIndex, (int) th.offset)); }
if (classIndex == -1) {
setNoTrait();
return; 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 { private class BufferedClass {
@@ -159,9 +205,22 @@ public class DecompiledEditorPane extends LineMarkedEditorPane implements MouseL
if (th.offset == traitId) { if (th.offset == traitId) {
try { try {
setCaretPosition(th.startPos + th.len - 1); setCaretPosition(th.startPos + th.len - 1);
setCaretPosition(th.startPos);
} catch (IllegalArgumentException iae) { } 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; return;
} }
} }
@@ -175,11 +234,12 @@ public class DecompiledEditorPane extends LineMarkedEditorPane implements MouseL
setCaretPosition(0); setCaretPosition(0);
} }
public DecompiledEditorPane() {
addMouseListener(this); public DecompiledEditorPane(ABCPanel abcPanel) {
setEditable(false); setEditable(false);
getCaret().setVisible(true); getCaret().setVisible(true);
addCaretListener(this); addCaretListener(this);
this.abcPanel = abcPanel;
} }
private List<DoABCTag> abcList; private List<DoABCTag> abcList;
@@ -208,6 +268,7 @@ public class DecompiledEditorPane extends LineMarkedEditorPane implements MouseL
highlights = bc.highlights; highlights = bc.highlights;
traitHighlights = bc.traitHighlights; traitHighlights = bc.traitHighlights;
methodHighlights = bc.methodHighlights; methodHighlights = bc.methodHighlights;
classHighlights = bc.classHighlights;
} }
setText(hilightedCode); setText(hilightedCode);
this.abc = abc; this.abc = abc;
@@ -223,24 +284,13 @@ public class DecompiledEditorPane extends LineMarkedEditorPane implements MouseL
setNoTrait(); setNoTrait();
} }
public int getClassIndex() {
return classIndex;
}
public void setABC(ABC abc) { public void setABC(ABC abc) {
this.abc = abc; this.abc = abc;
bufferedClasses.clear(); bufferedClasses.clear();
setText(""); 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) {
}
} }
@@ -39,16 +39,22 @@ public class DetailPanel extends JPanel implements ActionListener {
public static final String UNSUPPORTED_TRAIT_CARD = "-"; public static final String UNSUPPORTED_TRAIT_CARD = "-";
public static final String SLOT_CONST_TRAIT_CARD = "Slot/Const Trait"; public static final String SLOT_CONST_TRAIT_CARD = "Slot/Const Trait";
private JPanel innerPanel; 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 HashMap<String, JComponent> cardMap = new HashMap<String, JComponent>();
private String selectedCard; private String selectedCard;
private JLabel selectedLabel; 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(); innerPanel = new JPanel();
CardLayout layout = new CardLayout(); CardLayout layout = new CardLayout();
innerPanel.setLayout(layout); innerPanel.setLayout(layout);
methodTraitPanel = new MethodTraitDetailPanel(); methodTraitPanel = new MethodTraitDetailPanel(abcPanel);
cardMap.put(METHOD_TRAIT_CARD, methodTraitPanel); cardMap.put(METHOD_TRAIT_CARD, methodTraitPanel);
unsupportedTraitPanel = new JPanel(new BorderLayout()); unsupportedTraitPanel = new JPanel(new BorderLayout());
@@ -67,17 +73,22 @@ public class DetailPanel extends JPanel implements ActionListener {
setLayout(new BorderLayout()); setLayout(new BorderLayout());
add(innerPanel, BorderLayout.CENTER); add(innerPanel, BorderLayout.CENTER);
JPanel buttonsPanel = new JPanel(); buttonsPanel = new JPanel();
buttonsPanel.setLayout(new FlowLayout()); buttonsPanel.setLayout(new FlowLayout());
saveButton = new JButton("Save trait");
saveButton.setActionCommand("SAVEDETAIL"); saveButton.setActionCommand("SAVEDETAIL");
saveButton.addActionListener(this); saveButton.addActionListener(this);
editButton.setActionCommand("EDITDETAIL");
editButton.addActionListener(this);
cancelButton.setActionCommand("CANCELDETAIL");
cancelButton.addActionListener(this);
buttonsPanel.setBorder(new BevelBorder(BevelBorder.RAISED)); buttonsPanel.setBorder(new BevelBorder(BevelBorder.RAISED));
buttonsPanel.add(editButton);
buttonsPanel.add(saveButton); buttonsPanel.add(saveButton);
buttonsPanel.add(cancelButton);
add(buttonsPanel, BorderLayout.SOUTH); add(buttonsPanel, BorderLayout.SOUTH);
selectedCard = UNSUPPORTED_TRAIT_CARD; selectedCard = UNSUPPORTED_TRAIT_CARD;
layout.show(innerPanel, UNSUPPORTED_TRAIT_CARD); layout.show(innerPanel, UNSUPPORTED_TRAIT_CARD);
saveButton.setVisible(false); buttonsPanel.setVisible(false);
selectedLabel = new JLabel(""); selectedLabel = new JLabel("");
selectedLabel.setText(selectedCard); selectedLabel.setText(selectedCard);
selectedLabel.setBorder(new BevelBorder(BevelBorder.RAISED)); selectedLabel.setBorder(new BevelBorder(BevelBorder.RAISED));
@@ -85,21 +96,40 @@ public class DetailPanel extends JPanel implements ActionListener {
add(selectedLabel, BorderLayout.NORTH); 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) { public void showCard(String name) {
CardLayout layout = (CardLayout) innerPanel.getLayout(); CardLayout layout = (CardLayout) innerPanel.getLayout();
layout.show(innerPanel, name); layout.show(innerPanel, name);
saveButton.setVisible(cardMap.get(name) instanceof TraitDetail); boolean b = cardMap.get(name) instanceof TraitDetail;
buttonsPanel.setVisible(b);
selectedCard = name; selectedCard = name;
selectedLabel.setText(selectedCard); selectedLabel.setText(selectedCard);
} }
public void actionPerformed(ActionEvent e) { 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 (e.getActionCommand().equals("SAVEDETAIL")) {
if (cardMap.get(selectedCard) instanceof TraitDetail) { if (cardMap.get(selectedCard) instanceof TraitDetail) {
if (((TraitDetail) cardMap.get(selectedCard)).save()) { if (((TraitDetail) cardMap.get(selectedCard)).save()) {
int lasttrait = Main.mainFrame.abcPanel.decompiledTextArea.lastTraitIndex; int lasttrait = abcPanel.decompiledTextArea.lastTraitIndex;
Main.mainFrame.abcPanel.decompiledTextArea.reloadClass(); int lastclass = abcPanel.decompiledTextArea.getClassIndex();
Main.mainFrame.abcPanel.decompiledTextArea.gotoTrait(lasttrait); abcPanel.decompiledTextArea.reloadClass();
abcPanel.decompiledTextArea.setClassIndex(lastclass);
abcPanel.decompiledTextArea.gotoTrait(lasttrait);
JOptionPane.showMessageDialog(this, "Trait Successfully saved"); JOptionPane.showMessageDialog(this, "Trait Successfully saved");
} }
} }
@@ -42,9 +42,10 @@ public class MethodBodyParamsPanel extends JPanel implements ChangeListener {
public MethodBody body; public MethodBody body;
public JCheckBox autoFillCheckBox = new JCheckBox("Auto fill on code save (GLOBAL SETTING)"); public JCheckBox autoFillCheckBox = new JCheckBox("Auto fill on code save (GLOBAL SETTING)");
public JLabel experimentalLabel = new JLabel("...EXPERIMENTAL"); public JLabel experimentalLabel = new JLabel("...EXPERIMENTAL");
private ABCPanel abcPanel;
public MethodBodyParamsPanel() { public MethodBodyParamsPanel(ABCPanel abcPanel) {
setLayout(null); setLayout(null);
this.abcPanel=abcPanel;
maxStackLabel.setBounds(10, 10, 150, 25); maxStackLabel.setBounds(10, 10, 150, 25);
maxStackField.setBounds(10 + 150 + 10, 10, 75, 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_regs = Integer.parseInt(localCountField.getText());
body.max_scope_depth = Integer.parseInt(maxScopeDepthField.getText()); body.max_scope_depth = Integer.parseInt(maxScopeDepthField.getText());
} else { } 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); 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);
}
} }
@@ -17,6 +17,8 @@
package com.jpexs.asdec.abc.gui; package com.jpexs.asdec.abc.gui;
import com.jpexs.asdec.Main; 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.BorderLayout;
import java.awt.FlowLayout; import java.awt.FlowLayout;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
@@ -31,11 +33,35 @@ import javax.swing.JScrollPane;
*/ */
public class MethodCodePanel extends JPanel implements ActionListener { public class MethodCodePanel extends JPanel implements ActionListener {
public ASMSourceEditorPane sourceTextArea; private ASMSourceEditorPane sourceTextArea;
public JPanel buttonsPanel; public JPanel buttonsPanel;
public MethodCodePanel() { public void setIgnoreCarret(boolean ignoreCarret) {
sourceTextArea = new ASMSourceEditorPane(); sourceTextArea.setIgnoreCarret(ignoreCarret);
}
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()); setLayout(new BorderLayout());
add(new JScrollPane(sourceTextArea), BorderLayout.CENTER); 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); sourceTextArea.verify(Main.mainFrame.abcPanel.abc.constants, Main.mainFrame.abcPanel.abc);
} }
} }
public void setEditMode(boolean val) {
sourceTextArea.setEditable(val);
sourceTextArea.getCaret().setVisible(true);
}
} }
@@ -114,4 +114,9 @@ public class MethodInfoPanel extends JPanel {
} }
return true; return true;
} }
public void setEditMode(boolean val) {
returnTypeEditor.setEditable(val);
paramEditor.setEditable(val);
}
} }
@@ -29,10 +29,12 @@ public class MethodTraitDetailPanel extends JTabbedPane implements TraitDetail {
public MethodCodePanel methodCodePanel; public MethodCodePanel methodCodePanel;
public MethodBodyParamsPanel methodBodyParamsPanel; public MethodBodyParamsPanel methodBodyParamsPanel;
public MethodInfoPanel methodInfoPanel; public MethodInfoPanel methodInfoPanel;
public ABCPanel abcPanel;
public MethodTraitDetailPanel() { public MethodTraitDetailPanel(ABCPanel abcPanel) {
methodCodePanel = new MethodCodePanel(); this.abcPanel=abcPanel;
methodBodyParamsPanel = new MethodBodyParamsPanel(); methodCodePanel = new MethodCodePanel(abcPanel.decompiledTextArea);
methodBodyParamsPanel = new MethodBodyParamsPanel(abcPanel);
methodInfoPanel = new MethodInfoPanel(); methodInfoPanel = new MethodInfoPanel();
addTab("MethodInfo", methodInfoPanel); addTab("MethodInfo", methodInfoPanel);
addTab("MethodBody Code", methodCodePanel); addTab("MethodBody Code", methodCodePanel);
@@ -44,7 +46,7 @@ public class MethodTraitDetailPanel extends JTabbedPane implements TraitDetail {
if (!methodInfoPanel.save()) { if (!methodInfoPanel.save()) {
return false; return false;
} }
if (!methodCodePanel.sourceTextArea.save(Main.mainFrame.abcPanel.abc.constants)) { if (!methodCodePanel.save(abcPanel.abc.constants)) {
return false; return false;
} }
if (!methodBodyParamsPanel.save()) { if (!methodBodyParamsPanel.save()) {
@@ -53,4 +55,11 @@ public class MethodTraitDetailPanel extends JTabbedPane implements TraitDetail {
return true; return true;
} }
@Override
public void setEditMode(boolean val) {
methodCodePanel.setEditMode(val);
methodBodyParamsPanel.setEditMode(val);
methodInfoPanel.setEditMode(val);
}
} }
@@ -78,4 +78,9 @@ public class SlotConstTraitDetailPanel extends JPanel implements TraitDetail {
} }
return true; return true;
} }
@Override
public void setEditMode(boolean val) {
slotConstEditor.setEditable(val);
}
} }
@@ -22,5 +22,7 @@ package com.jpexs.asdec.abc.gui;
*/ */
public interface TraitDetail { public interface TraitDetail {
public void setEditMode(boolean val);
public boolean save(); public boolean save();
} }
@@ -30,13 +30,14 @@ public class TraitsList extends JList implements ListSelectionListener {
ABC abc; ABC abc;
List<DoABCTag> abcTags; List<DoABCTag> abcTags;
int classIndex = -1; int classIndex = -1;
private ABCPanel abcPanel;
public int getClassIndex() { public int getClassIndex() {
return classIndex; return classIndex;
} }
public TraitsList() { public TraitsList(ABCPanel abcPanel) {
addListSelectionListener(this); addListSelectionListener(this);
this.abcPanel=abcPanel;
setCellRenderer(new IconListRenderer()); setCellRenderer(new IconListRenderer());
} }
@@ -62,7 +63,7 @@ public class TraitsList extends JList implements ListSelectionListener {
int index = getSelectedIndex(); int index = getSelectedIndex();
Main.mainFrame.abcPanel.decompiledTextArea.gotoTrait(index); abcPanel.decompiledTextArea.gotoTrait(index);
} }
} }
@@ -45,8 +45,10 @@ public class UsageFrame extends JFrame implements ActionListener, MouseListener
private JList usageList; private JList usageList;
private UsageListModel usageListModel; private UsageListModel usageListModel;
private ABC abc; 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); List<MultinameUsage> usages = abc.findMultinameUsage(multinameIndex);
this.abc = abc; this.abc = abc;
usageListModel = new UsageListModel(abcTags, abc); usageListModel = new UsageListModel(abcTags, abc);
@@ -79,7 +81,7 @@ public class UsageFrame extends JFrame implements ActionListener, MouseListener
MultinameUsage usage = usageListModel.getUsage(usageList.getSelectedIndex()); MultinameUsage usage = usageListModel.getUsage(usageList.getSelectedIndex());
if (usage instanceof InsideClassMultinameUsage) { if (usage instanceof InsideClassMultinameUsage) {
InsideClassMultinameUsage icu = (InsideClassMultinameUsage) usage; InsideClassMultinameUsage icu = (InsideClassMultinameUsage) usage;
Main.mainFrame.abcPanel.classTree.selectClass(icu.classIndex); abcPanel.classTree.selectClass(icu.classIndex);
try { try {
Thread.sleep(100); Thread.sleep(100);
} catch (InterruptedException ex) { } 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); 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);
} }
} }
} }
@@ -60,10 +60,10 @@ public class ActionPanel extends JPanel implements TreeSelectionListener, Action
public JLabel decLabel = new JLabel("ActionScript source"); public JLabel decLabel = new JLabel("ActionScript source");
public List<Highlighting> decompiledHilights = new ArrayList<Highlighting>(); public List<Highlighting> decompiledHilights = new ArrayList<Highlighting>();
public List<Highlighting> disassembledHilights = 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) { public ActionPanel(List<Tag> list) {
this.list = list; this.list = list;
DefaultSyntaxKit.initKit(); DefaultSyntaxKit.initKit();
@@ -131,7 +131,7 @@ public class ActionPanel extends JPanel implements TreeSelectionListener, Action
editor.addCaretListener(new CaretListener() { editor.addCaretListener(new CaretListener() {
@Override @Override
public void caretUpdate(CaretEvent e) { public void caretUpdate(CaretEvent e) {
if(ignoreCarret){ if (ignoreCarret) {
return; return;
} }
editor.getCaret().setVisible(true); editor.getCaret().setVisible(true);
@@ -139,25 +139,16 @@ public class ActionPanel extends JPanel implements TreeSelectionListener, Action
Highlighting lastH = new Highlighting(0, 0, 0); Highlighting lastH = new Highlighting(0, 0, 0);
for (Highlighting h : disassembledHilights) { for (Highlighting h : disassembledHilights) {
if (pos < h.startPos) { 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; break;
} }
lastH = h; lastH = h;
} }
for (Highlighting h2 : decompiledHilights) { for (Highlighting h2 : decompiledHilights) {
if (h2.offset == lastH.offset) { if (h2.offset == lastH.offset) {
ignoreCarret=true; ignoreCarret = true;
decompiledEditor.setCaretPosition(h2.startPos); decompiledEditor.setCaretPosition(h2.startPos);
decompiledEditor.getCaret().setVisible(true); decompiledEditor.getCaret().setVisible(true);
ignoreCarret=false; ignoreCarret = false;
break; break;
} }
} }
@@ -166,10 +157,10 @@ public class ActionPanel extends JPanel implements TreeSelectionListener, Action
decompiledEditor.addCaretListener(new CaretListener() { decompiledEditor.addCaretListener(new CaretListener() {
@Override @Override
public void caretUpdate(CaretEvent e) { public void caretUpdate(CaretEvent e) {
if(ignoreCarret){ if (ignoreCarret) {
return; return;
} }
if(editMode){ if (editMode) {
return; return;
} }
decompiledEditor.getCaret().setVisible(true); 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)) { if ((pos >= h.startPos) && (pos < h.startPos + h.len)) {
for (Highlighting h2 : disassembledHilights) { for (Highlighting h2 : disassembledHilights) {
if (h2.offset == h.offset) { if (h2.offset == h.offset) {
ignoreCarret=true; ignoreCarret = true;
editor.setCaretPosition(h2.startPos); editor.setCaretPosition(h2.startPos);
editor.getCaret().setVisible(true); editor.getCaret().setVisible(true);
ignoreCarret=false; ignoreCarret = false;
break; break;
} }
} }
@@ -212,7 +203,7 @@ public class ActionPanel extends JPanel implements TreeSelectionListener, Action
public void run() { public void run() {
lastDisasm = asm.getASMSource(SWF.DEFAULT_VERSION); lastDisasm = asm.getASMSource(SWF.DEFAULT_VERSION);
disassembledHilights = Highlighting.getInstrHighlights(lastDisasm); disassembledHilights = Highlighting.getInstrHighlights(lastDisasm);
lastDisasm=Highlighting.stripHilights(lastDisasm); lastDisasm = Highlighting.stripHilights(lastDisasm);
editor.setText(lastDisasm); editor.setText(lastDisasm);
if (Main.DO_DECOMPILE) { if (Main.DO_DECOMPILE) {
List<com.jpexs.asdec.action.Action> as = asm.getActions(SWF.DEFAULT_VERSION); 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; return ret;
} }
public void setEditMode(boolean val){ public void setEditMode(boolean val) {
if(val){ if (val) {
editor.setEditable(true); editor.setEditable(true);
saveButton.setVisible(true); saveButton.setVisible(true);
editButton.setVisible(false); editButton.setVisible(false);
cancelButton.setVisible(true); cancelButton.setVisible(true);
editor.getCaret().setVisible(true); editor.getCaret().setVisible(true);
}else{ } else {
editor.setEditable(false); editor.setEditable(false);
saveButton.setVisible(false); saveButton.setVisible(false);
editButton.setVisible(true); editButton.setVisible(true);
cancelButton.setVisible(false); cancelButton.setVisible(false);
editor.getCaret().setVisible(true); editor.getCaret().setVisible(true);
} }
editMode=val; editMode = val;
} }
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
if (e.getActionCommand().equals("EDITACTION")) { if (e.getActionCommand().equals("EDITACTION")) {
setEditMode(true); setEditMode(true);
}else } else if (e.getActionCommand().equals("CANCELACTION")) {
if (e.getActionCommand().equals("CANCELACTION")) {
setEditMode(false); setEditMode(false);
editor.setText(lastDisasm); editor.setText(lastDisasm);
}else } else if (e.getActionCommand().equals("SAVEACTION")) {
if (e.getActionCommand().equals("SAVEACTION")) {
TagNode ti = (TagNode) tagTree.getLastSelectedPathComponent(); TagNode ti = (TagNode) tagTree.getLastSelectedPathComponent();
if (ti.tag instanceof ASMSource) { if (ti.tag instanceof ASMSource) {
ASMSource dat = (ASMSource) ti.tag; ASMSource dat = (ASMSource) ti.tag;