AS3: Edit obfuscated identifiers

build script: running from lib too, clean lib from gui clean
This commit is contained in:
Jindra Petřík
2014-08-24 20:27:48 +02:00
parent 04922aaf69
commit 226eb3e7a6
42 changed files with 777 additions and 676 deletions
@@ -322,7 +322,7 @@ public class DecompiledEditorPane extends LineMarkedEditorPane implements CaretL
String name = "";
if (abc != null) {
if (classIndex > -1) {
name = abc.instance_info.get(classIndex).getName(abc.constants).getNameWithNamespace(abc.constants);
name = abc.instance_info.get(classIndex).getName(abc.constants).getNameWithNamespace(abc.constants,false);
}
}
currentTrait = null;
@@ -333,7 +333,7 @@ public class DecompiledEditorPane extends LineMarkedEditorPane implements CaretL
currentTrait = abc.findTraitByTraitId(classIndex, lastTraitIndex);
isStatic = abc.isStaticTraitId(classIndex, lastTraitIndex);
if (currentTrait != null) {
name += ":" + currentTrait.getName(abc).getName(abc.constants, new ArrayList<String>());
name += ":" + currentTrait.getName(abc).getName(abc.constants, new ArrayList<String>(),false);
}
}
}
@@ -371,11 +371,11 @@ public class DecompiledEditorPane extends LineMarkedEditorPane implements CaretL
String name = "";
currentTrait = null;
if (abc != null) {
name = abc.instance_info.get(classIndex).getName(abc.constants).getNameWithNamespace(abc.constants);
name = abc.instance_info.get(classIndex).getName(abc.constants).getNameWithNamespace(abc.constants,false);
currentTrait = abc.findTraitByTraitId(classIndex, lastTraitIndex);
isStatic = abc.isStaticTraitId(classIndex, lastTraitIndex);
if (currentTrait != null) {
name += ":" + currentTrait.getName(abc).getName(abc.constants, new ArrayList<String>());
name += ":" + currentTrait.getName(abc).getName(abc.constants, new ArrayList<String>(),false);
}
}
@@ -1,215 +1,215 @@
/*
* Copyright (C) 2010-2014 JPEXS
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.jpexs.decompiler.flash.gui.abc;
import com.jpexs.decompiler.flash.AppStrings;
import com.jpexs.decompiler.flash.abc.types.traits.Trait;
import com.jpexs.decompiler.flash.gui.HeaderLabel;
import com.jpexs.decompiler.flash.gui.View;
import com.jpexs.helpers.CancellableWorker;
import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.FlowLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.HashMap;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import javax.swing.border.BevelBorder;
/**
*
* @author JPEXS
*/
public class DetailPanel extends JPanel implements ActionListener {
static final String ACTION_SAVE_DETAIL = "SAVEDETAIL";
static final String ACTION_EDIT_DETAIL = "EDITDETAIL";
static final String ACTION_CANCEL_DETAIL = "CANCELDETAIL";
public MethodTraitDetailPanel methodTraitPanel;
public JPanel unsupportedTraitPanel;
public SlotConstTraitDetailPanel slotConstTraitPanel;
public static final String METHOD_TRAIT_CARD = AppStrings.translate("abc.detail.methodtrait");
public static final String UNSUPPORTED_TRAIT_CARD = AppStrings.translate("abc.detail.unsupported");
public static final String SLOT_CONST_TRAIT_CARD = AppStrings.translate("abc.detail.slotconsttrait");
private final JPanel innerPanel;
public JButton saveButton = new JButton(AppStrings.translate("button.save"), View.getIcon("save16"));
public JButton editButton = new JButton(AppStrings.translate("button.edit"), View.getIcon("edit16"));
public JButton cancelButton = new JButton(AppStrings.translate("button.cancel"), View.getIcon("cancel16"));
private final HashMap<String, JComponent> cardMap = new HashMap<>();
private String selectedCard;
private final JLabel selectedLabel;
private boolean editMode = false;
private final JPanel buttonsPanel;
private final ABCPanel abcPanel;
private final JLabel traitNameLabel;
public DetailPanel(ABCPanel abcPanel) {
this.abcPanel = abcPanel;
innerPanel = new JPanel();
CardLayout layout = new CardLayout();
innerPanel.setLayout(layout);
methodTraitPanel = new MethodTraitDetailPanel(abcPanel);
cardMap.put(METHOD_TRAIT_CARD, methodTraitPanel);
unsupportedTraitPanel = new JPanel(new BorderLayout());
JLabel unsup = new JLabel(AppStrings.translate("info.selecttrait"), SwingConstants.CENTER);
unsupportedTraitPanel.add(unsup, BorderLayout.CENTER);
cardMap.put(UNSUPPORTED_TRAIT_CARD, unsupportedTraitPanel);
slotConstTraitPanel = new SlotConstTraitDetailPanel(abcPanel.decompiledTextArea);
cardMap.put(SLOT_CONST_TRAIT_CARD, slotConstTraitPanel);
for (String key : cardMap.keySet()) {
innerPanel.add(cardMap.get(key), key);
}
setLayout(new BorderLayout());
add(innerPanel, BorderLayout.CENTER);
editButton.setMargin(new Insets(3, 3, 3, 10));
saveButton.setMargin(new Insets(3, 3, 3, 10));
cancelButton.setMargin(new Insets(3, 3, 3, 10));
buttonsPanel = new JPanel();
buttonsPanel.setLayout(new FlowLayout());
saveButton.setActionCommand(ACTION_SAVE_DETAIL);
saveButton.addActionListener(this);
editButton.setActionCommand(ACTION_EDIT_DETAIL);
editButton.addActionListener(this);
cancelButton.setActionCommand(ACTION_CANCEL_DETAIL);
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);
buttonsPanel.setVisible(false);
selectedLabel = new HeaderLabel("");
selectedLabel.setText(selectedCard);
//selectedLabel.setBorder(new BevelBorder(BevelBorder.RAISED));
selectedLabel.setHorizontalAlignment(SwingConstants.CENTER);
JPanel topPanel = new JPanel(new BorderLayout());
topPanel.add(selectedLabel, BorderLayout.NORTH);
traitNameLabel = new JLabel("");
JPanel traitInfoPanel = new JPanel();
traitInfoPanel.setLayout(new BoxLayout(traitInfoPanel, BoxLayout.LINE_AXIS));
//traitInfoPanel.add(new JLabel(" " + translate("abc.detail.traitname")));
traitInfoPanel.add(traitNameLabel);
topPanel.add(traitInfoPanel, BorderLayout.CENTER);
add(topPanel, BorderLayout.NORTH);
}
public void setEditMode(boolean val) {
slotConstTraitPanel.setEditMode(val);
methodTraitPanel.setEditMode(val);
saveButton.setVisible(val);
editButton.setVisible(!val);
cancelButton.setVisible(val);
editMode = val;
if (val) {
selectedLabel.setIcon(View.getIcon("editing16"));
} else {
selectedLabel.setIcon(null);
}
}
public void showCard(final String name, final Trait trait) {
View.execInEventDispatch(new Runnable() {
@Override
public void run() {
CardLayout layout = (CardLayout) innerPanel.getLayout();
layout.show(innerPanel, name);
boolean b = cardMap.get(name) instanceof TraitDetail;
buttonsPanel.setVisible(b);
TraitDetail newDetail = null;
if (b) {
newDetail = (TraitDetail) cardMap.get(name);
}
for (JComponent v : cardMap.values()) {
if (v instanceof TraitDetail) {
if (v != newDetail) {
TraitDetail oldDetail = (TraitDetail) v;
oldDetail.setActive(false);
}
}
}
if (newDetail != null) {
newDetail.setActive(true);
}
selectedCard = name;
selectedLabel.setText(selectedCard);
if (trait == null) {
traitNameLabel.setText("-");
} else {
traitNameLabel.setText(trait.getName(abcPanel.abc).getName(abcPanel.abc.constants, new ArrayList<String>()));
}
}
});
}
@Override
public void actionPerformed(ActionEvent e) {
switch (e.getActionCommand()) {
case ACTION_EDIT_DETAIL:
setEditMode(true);
methodTraitPanel.methodCodePanel.focusEditor();
break;
case ACTION_CANCEL_DETAIL:
setEditMode(false);
abcPanel.decompiledTextArea.resetEditing();
break;
case ACTION_SAVE_DETAIL:
if (cardMap.get(selectedCard) instanceof TraitDetail) {
if (((TraitDetail) cardMap.get(selectedCard)).save()) {
CancellableWorker worker = new CancellableWorker() {
@Override
public Void doInBackground() throws Exception {
int lasttrait = abcPanel.decompiledTextArea.lastTraitIndex;
abcPanel.decompiledTextArea.reloadClass();
abcPanel.decompiledTextArea.gotoTrait(lasttrait);
return null;
}
@Override
protected void done() {
setEditMode(false);
View.showMessageDialog(null, AppStrings.translate("message.trait.saved"));
}
};
worker.execute();
}
}
break;
}
}
}
/*
* Copyright (C) 2010-2014 JPEXS
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.jpexs.decompiler.flash.gui.abc;
import com.jpexs.decompiler.flash.AppStrings;
import com.jpexs.decompiler.flash.abc.types.traits.Trait;
import com.jpexs.decompiler.flash.gui.HeaderLabel;
import com.jpexs.decompiler.flash.gui.View;
import com.jpexs.helpers.CancellableWorker;
import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.FlowLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.HashMap;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import javax.swing.border.BevelBorder;
/**
*
* @author JPEXS
*/
public class DetailPanel extends JPanel implements ActionListener {
static final String ACTION_SAVE_DETAIL = "SAVEDETAIL";
static final String ACTION_EDIT_DETAIL = "EDITDETAIL";
static final String ACTION_CANCEL_DETAIL = "CANCELDETAIL";
public MethodTraitDetailPanel methodTraitPanel;
public JPanel unsupportedTraitPanel;
public SlotConstTraitDetailPanel slotConstTraitPanel;
public static final String METHOD_TRAIT_CARD = AppStrings.translate("abc.detail.methodtrait");
public static final String UNSUPPORTED_TRAIT_CARD = AppStrings.translate("abc.detail.unsupported");
public static final String SLOT_CONST_TRAIT_CARD = AppStrings.translate("abc.detail.slotconsttrait");
private final JPanel innerPanel;
public JButton saveButton = new JButton(AppStrings.translate("button.save"), View.getIcon("save16"));
public JButton editButton = new JButton(AppStrings.translate("button.edit"), View.getIcon("edit16"));
public JButton cancelButton = new JButton(AppStrings.translate("button.cancel"), View.getIcon("cancel16"));
private final HashMap<String, JComponent> cardMap = new HashMap<>();
private String selectedCard;
private final JLabel selectedLabel;
private boolean editMode = false;
private final JPanel buttonsPanel;
private final ABCPanel abcPanel;
private final JLabel traitNameLabel;
public DetailPanel(ABCPanel abcPanel) {
this.abcPanel = abcPanel;
innerPanel = new JPanel();
CardLayout layout = new CardLayout();
innerPanel.setLayout(layout);
methodTraitPanel = new MethodTraitDetailPanel(abcPanel);
cardMap.put(METHOD_TRAIT_CARD, methodTraitPanel);
unsupportedTraitPanel = new JPanel(new BorderLayout());
JLabel unsup = new JLabel(AppStrings.translate("info.selecttrait"), SwingConstants.CENTER);
unsupportedTraitPanel.add(unsup, BorderLayout.CENTER);
cardMap.put(UNSUPPORTED_TRAIT_CARD, unsupportedTraitPanel);
slotConstTraitPanel = new SlotConstTraitDetailPanel(abcPanel.decompiledTextArea);
cardMap.put(SLOT_CONST_TRAIT_CARD, slotConstTraitPanel);
for (String key : cardMap.keySet()) {
innerPanel.add(cardMap.get(key), key);
}
setLayout(new BorderLayout());
add(innerPanel, BorderLayout.CENTER);
editButton.setMargin(new Insets(3, 3, 3, 10));
saveButton.setMargin(new Insets(3, 3, 3, 10));
cancelButton.setMargin(new Insets(3, 3, 3, 10));
buttonsPanel = new JPanel();
buttonsPanel.setLayout(new FlowLayout());
saveButton.setActionCommand(ACTION_SAVE_DETAIL);
saveButton.addActionListener(this);
editButton.setActionCommand(ACTION_EDIT_DETAIL);
editButton.addActionListener(this);
cancelButton.setActionCommand(ACTION_CANCEL_DETAIL);
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);
buttonsPanel.setVisible(false);
selectedLabel = new HeaderLabel("");
selectedLabel.setText(selectedCard);
//selectedLabel.setBorder(new BevelBorder(BevelBorder.RAISED));
selectedLabel.setHorizontalAlignment(SwingConstants.CENTER);
JPanel topPanel = new JPanel(new BorderLayout());
topPanel.add(selectedLabel, BorderLayout.NORTH);
traitNameLabel = new JLabel("");
JPanel traitInfoPanel = new JPanel();
traitInfoPanel.setLayout(new BoxLayout(traitInfoPanel, BoxLayout.LINE_AXIS));
//traitInfoPanel.add(new JLabel(" " + translate("abc.detail.traitname")));
traitInfoPanel.add(traitNameLabel);
topPanel.add(traitInfoPanel, BorderLayout.CENTER);
add(topPanel, BorderLayout.NORTH);
}
public void setEditMode(boolean val) {
slotConstTraitPanel.setEditMode(val);
methodTraitPanel.setEditMode(val);
saveButton.setVisible(val);
editButton.setVisible(!val);
cancelButton.setVisible(val);
editMode = val;
if (val) {
selectedLabel.setIcon(View.getIcon("editing16"));
} else {
selectedLabel.setIcon(null);
}
}
public void showCard(final String name, final Trait trait) {
View.execInEventDispatch(new Runnable() {
@Override
public void run() {
CardLayout layout = (CardLayout) innerPanel.getLayout();
layout.show(innerPanel, name);
boolean b = cardMap.get(name) instanceof TraitDetail;
buttonsPanel.setVisible(b);
TraitDetail newDetail = null;
if (b) {
newDetail = (TraitDetail) cardMap.get(name);
}
for (JComponent v : cardMap.values()) {
if (v instanceof TraitDetail) {
if (v != newDetail) {
TraitDetail oldDetail = (TraitDetail) v;
oldDetail.setActive(false);
}
}
}
if (newDetail != null) {
newDetail.setActive(true);
}
selectedCard = name;
selectedLabel.setText(selectedCard);
if (trait == null) {
traitNameLabel.setText("-");
} else {
traitNameLabel.setText(trait.getName(abcPanel.abc).getName(abcPanel.abc.constants, new ArrayList<String>(),false));
}
}
});
}
@Override
public void actionPerformed(ActionEvent e) {
switch (e.getActionCommand()) {
case ACTION_EDIT_DETAIL:
setEditMode(true);
methodTraitPanel.methodCodePanel.focusEditor();
break;
case ACTION_CANCEL_DETAIL:
setEditMode(false);
abcPanel.decompiledTextArea.resetEditing();
break;
case ACTION_SAVE_DETAIL:
if (cardMap.get(selectedCard) instanceof TraitDetail) {
if (((TraitDetail) cardMap.get(selectedCard)).save()) {
CancellableWorker worker = new CancellableWorker() {
@Override
public Void doInBackground() throws Exception {
int lasttrait = abcPanel.decompiledTextArea.lastTraitIndex;
abcPanel.decompiledTextArea.reloadClass();
abcPanel.decompiledTextArea.gotoTrait(lasttrait);
return null;
}
@Override
protected void done() {
setEditMode(false);
View.showMessageDialog(null, AppStrings.translate("message.trait.saved"));
}
};
worker.execute();
}
}
break;
}
}
}
@@ -1,142 +1,142 @@
/*
* Copyright (C) 2010-2014 JPEXS
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.jpexs.decompiler.flash.gui.abc;
import com.jpexs.decompiler.flash.AppStrings;
import com.jpexs.decompiler.flash.abc.ABC;
import com.jpexs.decompiler.flash.abc.types.traits.Trait;
import com.jpexs.decompiler.flash.abc.types.traits.TraitMethodGetterSetter;
import com.jpexs.decompiler.flash.abc.types.traits.TraitSlotConst;
import com.jpexs.decompiler.flash.configuration.Configuration;
import com.jpexs.decompiler.flash.exporters.modes.ScriptExportMode;
import com.jpexs.decompiler.flash.helpers.HilightedTextWriter;
import com.jpexs.decompiler.flash.helpers.NulWriter;
import com.jpexs.decompiler.flash.tags.ABCContainerTag;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author JPEXS
*/
public class TraitsListItem {
private final Type type;
private final boolean isStatic;
private final List<ABCContainerTag> abcTags;
private final ABC abc;
private final int classIndex;
private final int index;
private final int scriptIndex;
public String STR_INSTANCE_INITIALIZER = AppStrings.translate("abc.traitslist.instanceinitializer");
public String STR_CLASS_INITIALIZER = AppStrings.translate("abc.traitslist.classinitializer");
public TraitsListItem(Type type, int index, boolean isStatic, List<ABCContainerTag> abcTags, ABC abc, int classIndex, int scriptIndex) {
this.type = type;
this.index = index;
this.isStatic = isStatic;
this.abcTags = abcTags;
this.abc = abc;
this.classIndex = classIndex;
this.scriptIndex = scriptIndex;
}
public int getGlobalTraitId() {
if (type == Type.INITIALIZER) {
if (!isStatic) {
return abc.class_info.get(classIndex).static_traits.traits.size() + abc.instance_info.get(classIndex).instance_traits.traits.size();
} else {
return abc.class_info.get(classIndex).static_traits.traits.size() + abc.instance_info.get(classIndex).instance_traits.traits.size() + 1;
}
}
if (isStatic) {
return index;
} else {
return abc.class_info.get(classIndex).static_traits.traits.size() + index;
}
}
public String toStringName() {
if ((type != Type.INITIALIZER) && isStatic) {
return abc.class_info.get(classIndex).static_traits.traits.get(index).getName(abc).getName(abc.constants, new ArrayList<String>());
} else if ((type != Type.INITIALIZER) && (!isStatic)) {
return abc.instance_info.get(classIndex).instance_traits.traits.get(index).getName(abc).getName(abc.constants, new ArrayList<String>());
} else if (!isStatic) {
return "__" + STR_INSTANCE_INITIALIZER;
} else {
return "__" + STR_CLASS_INITIALIZER;
}
}
@Override
public String toString() {
String s = "";
try {
if ((type != Type.INITIALIZER) && isStatic) {
abc.class_info.get(classIndex).static_traits.traits.get(index).convertHeader(null, "", abcTags, abc, true, ScriptExportMode.AS, scriptIndex, classIndex, new NulWriter(), new ArrayList<String>(), false);
HilightedTextWriter writer = new HilightedTextWriter(Configuration.getCodeFormatting(), false);
abc.class_info.get(classIndex).static_traits.traits.get(index).toStringHeader(null, "", abcTags, abc, true, ScriptExportMode.AS, scriptIndex, classIndex, writer, new ArrayList<String>(), false);
s = writer.toString();
} else if ((type != Type.INITIALIZER) && (!isStatic)) {
abc.instance_info.get(classIndex).instance_traits.traits.get(index).convertHeader(null, "", abcTags, abc, false, ScriptExportMode.AS, scriptIndex, classIndex, new NulWriter(), new ArrayList<String>(), false);
HilightedTextWriter writer = new HilightedTextWriter(Configuration.getCodeFormatting(), false);
abc.instance_info.get(classIndex).instance_traits.traits.get(index).toStringHeader(null, "", abcTags, abc, false, ScriptExportMode.AS, scriptIndex, classIndex, writer, new ArrayList<String>(), false);
s = writer.toString();
} else if (!isStatic) {
s = STR_INSTANCE_INITIALIZER;
} else {
s = STR_CLASS_INITIALIZER;
}
} catch (InterruptedException ex) {
Logger.getLogger(TraitsListItem.class.getName()).log(Level.SEVERE, null, ex);
}
s = s.replaceAll("[ \r\n]+", " ");
return s;
}
public Type getType() {
return type;
}
public boolean isStatic() {
return isStatic;
}
public enum Type {
METHOD,
VAR,
CONST,
INITIALIZER;
public static Type getTypeForTrait(Trait t) {
if (t instanceof TraitMethodGetterSetter) {
return METHOD;
}
if (t instanceof TraitSlotConst) {
if (((TraitSlotConst) t).isConst()) {
return CONST;
} else {
return VAR;
}
}
return null;
}
}
}
/*
* Copyright (C) 2010-2014 JPEXS
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.jpexs.decompiler.flash.gui.abc;
import com.jpexs.decompiler.flash.AppStrings;
import com.jpexs.decompiler.flash.abc.ABC;
import com.jpexs.decompiler.flash.abc.types.traits.Trait;
import com.jpexs.decompiler.flash.abc.types.traits.TraitMethodGetterSetter;
import com.jpexs.decompiler.flash.abc.types.traits.TraitSlotConst;
import com.jpexs.decompiler.flash.configuration.Configuration;
import com.jpexs.decompiler.flash.exporters.modes.ScriptExportMode;
import com.jpexs.decompiler.flash.helpers.HilightedTextWriter;
import com.jpexs.decompiler.flash.helpers.NulWriter;
import com.jpexs.decompiler.flash.tags.ABCContainerTag;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author JPEXS
*/
public class TraitsListItem {
private final Type type;
private final boolean isStatic;
private final List<ABCContainerTag> abcTags;
private final ABC abc;
private final int classIndex;
private final int index;
private final int scriptIndex;
public String STR_INSTANCE_INITIALIZER = AppStrings.translate("abc.traitslist.instanceinitializer");
public String STR_CLASS_INITIALIZER = AppStrings.translate("abc.traitslist.classinitializer");
public TraitsListItem(Type type, int index, boolean isStatic, List<ABCContainerTag> abcTags, ABC abc, int classIndex, int scriptIndex) {
this.type = type;
this.index = index;
this.isStatic = isStatic;
this.abcTags = abcTags;
this.abc = abc;
this.classIndex = classIndex;
this.scriptIndex = scriptIndex;
}
public int getGlobalTraitId() {
if (type == Type.INITIALIZER) {
if (!isStatic) {
return abc.class_info.get(classIndex).static_traits.traits.size() + abc.instance_info.get(classIndex).instance_traits.traits.size();
} else {
return abc.class_info.get(classIndex).static_traits.traits.size() + abc.instance_info.get(classIndex).instance_traits.traits.size() + 1;
}
}
if (isStatic) {
return index;
} else {
return abc.class_info.get(classIndex).static_traits.traits.size() + index;
}
}
public String toStringName() {
if ((type != Type.INITIALIZER) && isStatic) {
return abc.class_info.get(classIndex).static_traits.traits.get(index).getName(abc).getName(abc.constants, new ArrayList<String>(),false);
} else if ((type != Type.INITIALIZER) && (!isStatic)) {
return abc.instance_info.get(classIndex).instance_traits.traits.get(index).getName(abc).getName(abc.constants, new ArrayList<String>(),false);
} else if (!isStatic) {
return "__" + STR_INSTANCE_INITIALIZER;
} else {
return "__" + STR_CLASS_INITIALIZER;
}
}
@Override
public String toString() {
String s = "";
try {
if ((type != Type.INITIALIZER) && isStatic) {
abc.class_info.get(classIndex).static_traits.traits.get(index).convertHeader(null, "", abcTags, abc, true, ScriptExportMode.AS, scriptIndex, classIndex, new NulWriter(), new ArrayList<String>(), false);
HilightedTextWriter writer = new HilightedTextWriter(Configuration.getCodeFormatting(), false);
abc.class_info.get(classIndex).static_traits.traits.get(index).toStringHeader(null, "", abcTags, abc, true, ScriptExportMode.AS, scriptIndex, classIndex, writer, new ArrayList<String>(), false);
s = writer.toString();
} else if ((type != Type.INITIALIZER) && (!isStatic)) {
abc.instance_info.get(classIndex).instance_traits.traits.get(index).convertHeader(null, "", abcTags, abc, false, ScriptExportMode.AS, scriptIndex, classIndex, new NulWriter(), new ArrayList<String>(), false);
HilightedTextWriter writer = new HilightedTextWriter(Configuration.getCodeFormatting(), false);
abc.instance_info.get(classIndex).instance_traits.traits.get(index).toStringHeader(null, "", abcTags, abc, false, ScriptExportMode.AS, scriptIndex, classIndex, writer, new ArrayList<String>(), false);
s = writer.toString();
} else if (!isStatic) {
s = STR_INSTANCE_INITIALIZER;
} else {
s = STR_CLASS_INITIALIZER;
}
} catch (InterruptedException ex) {
Logger.getLogger(TraitsListItem.class.getName()).log(Level.SEVERE, null, ex);
}
s = s.replaceAll("[ \r\n]+", " ");
return s;
}
public Type getType() {
return type;
}
public boolean isStatic() {
return isStatic;
}
public enum Type {
METHOD,
VAR,
CONST,
INITIALIZER;
public static Type getTypeForTrait(Trait t) {
if (t instanceof TraitMethodGetterSetter) {
return METHOD;
}
if (t instanceof TraitSlotConst) {
if (((TraitSlotConst) t).isConst()) {
return CONST;
} else {
return VAR;
}
}
return null;
}
}
}
@@ -93,7 +93,7 @@ public class UsageFrame extends AppDialog implements ActionListener, MouseListen
cont.add(new JScrollPane(usageList), BorderLayout.CENTER);
cont.add(buttonsPanel, BorderLayout.SOUTH);
setSize(400, 300);
setTitle((definitions ? translate("dialog.title.declaration") : translate("dialog.title")) + abc.constants.getMultiname(multinameIndex).getNameWithNamespace(abc.constants));
setTitle((definitions ? translate("dialog.title.declaration") : translate("dialog.title")) + abc.constants.getMultiname(multinameIndex).getNameWithNamespace(abc.constants,false));
View.centerScreen(this);
View.setWindowIcon(this);
}
@@ -134,7 +134,7 @@ public class UsageFrame extends AppDialog implements ActionListener, MouseListen
settrait.run();
} else {
abcPanel.decompiledTextArea.addScriptListener(settrait);
abcPanel.hilightScript(abcPanel.swf, abcPanel.abc.instance_info.get(icu.classIndex).getName(abcPanel.abc.constants).getNameWithNamespace(abcPanel.abc.constants));
abcPanel.hilightScript(abcPanel.swf, abcPanel.abc.instance_info.get(icu.classIndex).getName(abcPanel.abc.constants).getNameWithNamespace(abcPanel.abc.constants,false));
}
}
}
@@ -1,184 +1,184 @@
/*
* Copyright (C) 2010-2014 JPEXS
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.jpexs.decompiler.flash.gui.abc.tablemodels;
import com.jpexs.decompiler.flash.abc.ABC;
import java.util.ArrayList;
import javax.swing.event.TableModelListener;
import javax.swing.table.TableModel;
public class MultinameTableModel implements TableModel {
private final ABC abc;
private static final String[] columnNames = new String[]{"Index", "Kind", "Name", "Namespace", "NamespaceSet"};
private static final Class[] classes = new Class[]{Long.class, String.class, String.class, String.class, String.class};
public MultinameTableModel(ABC abc) {
this.abc = abc;
}
/**
* Returns the number of rows in the model. A <code>JTable</code> uses this
* method to determine how many rows it should display. This method should
* be quick, as it is called frequently during rendering.
*
* @return the number of rows in the model
* @see #getColumnCount
*/
@Override
public int getRowCount() {
if (abc == null) {
return 0;
}
return abc.constants.getMultinameCount();
}
/**
* Returns the number of columns in the model. A <code>JTable</code> uses
* this method to determine how many columns it should create and display by
* default.
*
* @return the number of columns in the model
* @see #getRowCount
*/
@Override
public int getColumnCount() {
return 5;
}
/**
* Returns the name of the column at <code>columnIndex</code>. This is used
* to initialize the table's column header name. Note: this name does not
* need to be unique; two columns in a table can have the same name.
*
* @param columnIndex the index of the column
* @return the name of the column
*/
@Override
public String getColumnName(int columnIndex) {
return columnNames[columnIndex];
}
/**
* Returns the most specific superclass for all the cell values in the
* column. This is used by the <code>JTable</code> to set up a default
* renderer and editor for the column.
*
* @param columnIndex the index of the column
* @return the common ancestor class of the object values in the model.
*/
@Override
public Class<?> getColumnClass(int columnIndex) {
return classes[columnIndex];
}
/**
* Returns true if the cell at <code>rowIndex</code> and
* <code>columnIndex</code> is editable. Otherwise, <code>setValueAt</code>
* on the cell will not change the value of that cell.
*
* @param rowIndex the row whose value to be queried
* @param columnIndex the column whose value to be queried
* @return true if the cell is editable
* @see #setValueAt
*/
@Override
public boolean isCellEditable(int rowIndex, int columnIndex) {
return false;
}
/**
* Returns the value for the cell at <code>columnIndex</code> and
* <code>rowIndex</code>.
*
* @param rowIndex the row whose value is to be queried
* @param columnIndex the column whose value is to be queried
* @return the value Object at the specified cell
*/
@Override
public Object getValueAt(int rowIndex, int columnIndex) {
switch (columnIndex) {
case 0:
return rowIndex;
case 1:
if (rowIndex == 0) {
return "";
}
return abc.constants.getMultiname(rowIndex).getKindStr();
case 2:
if (rowIndex == 0) {
return "";
}
if (abc.constants.getMultiname(rowIndex).name_index == -1) {
return "";
}
return abc.constants.getMultiname(rowIndex).getName(abc.constants, new ArrayList<String>());
case 3:
if (rowIndex == 0) {
return "";
}
if (abc.constants.getMultiname(rowIndex).namespace_index <= 0) {
return "-";
}
return abc.constants.getMultiname(rowIndex).getNamespace(abc.constants).getNameWithKind(abc.constants);
case 4:
if (rowIndex == 0) {
return "";
}
if (abc.constants.getMultiname(rowIndex).namespace_set_index <= 0) {
return "-";
}
return abc.constants.getMultiname(rowIndex).getNamespaceSet(abc.constants).toString(abc.constants);
default:
return null;
}
}
/**
* Sets the value in the cell at <code>columnIndex</code> and
* <code>rowIndex</code> to <code>aValue</code>.
*
* @param aValue the new value
* @param rowIndex the row whose value is to be changed
* @param columnIndex the column whose value is to be changed
* @see #getValueAt
* @see #isCellEditable
*/
@Override
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
}
/**
* Adds a listener to the list that is notified each time a change to the
* data model occurs.
*
* @param l the TableModelListener
*/
@Override
public void addTableModelListener(TableModelListener l) {
}
/**
* Removes a listener from the list that is notified each time a change to
* the data model occurs.
*
* @param l the TableModelListener
*/
@Override
public void removeTableModelListener(TableModelListener l) {
}
}
/*
* Copyright (C) 2010-2014 JPEXS
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.jpexs.decompiler.flash.gui.abc.tablemodels;
import com.jpexs.decompiler.flash.abc.ABC;
import java.util.ArrayList;
import javax.swing.event.TableModelListener;
import javax.swing.table.TableModel;
public class MultinameTableModel implements TableModel {
private final ABC abc;
private static final String[] columnNames = new String[]{"Index", "Kind", "Name", "Namespace", "NamespaceSet"};
private static final Class[] classes = new Class[]{Long.class, String.class, String.class, String.class, String.class};
public MultinameTableModel(ABC abc) {
this.abc = abc;
}
/**
* Returns the number of rows in the model. A <code>JTable</code> uses this
* method to determine how many rows it should display. This method should
* be quick, as it is called frequently during rendering.
*
* @return the number of rows in the model
* @see #getColumnCount
*/
@Override
public int getRowCount() {
if (abc == null) {
return 0;
}
return abc.constants.getMultinameCount();
}
/**
* Returns the number of columns in the model. A <code>JTable</code> uses
* this method to determine how many columns it should create and display by
* default.
*
* @return the number of columns in the model
* @see #getRowCount
*/
@Override
public int getColumnCount() {
return 5;
}
/**
* Returns the name of the column at <code>columnIndex</code>. This is used
* to initialize the table's column header name. Note: this name does not
* need to be unique; two columns in a table can have the same name.
*
* @param columnIndex the index of the column
* @return the name of the column
*/
@Override
public String getColumnName(int columnIndex) {
return columnNames[columnIndex];
}
/**
* Returns the most specific superclass for all the cell values in the
* column. This is used by the <code>JTable</code> to set up a default
* renderer and editor for the column.
*
* @param columnIndex the index of the column
* @return the common ancestor class of the object values in the model.
*/
@Override
public Class<?> getColumnClass(int columnIndex) {
return classes[columnIndex];
}
/**
* Returns true if the cell at <code>rowIndex</code> and
* <code>columnIndex</code> is editable. Otherwise, <code>setValueAt</code>
* on the cell will not change the value of that cell.
*
* @param rowIndex the row whose value to be queried
* @param columnIndex the column whose value to be queried
* @return true if the cell is editable
* @see #setValueAt
*/
@Override
public boolean isCellEditable(int rowIndex, int columnIndex) {
return false;
}
/**
* Returns the value for the cell at <code>columnIndex</code> and
* <code>rowIndex</code>.
*
* @param rowIndex the row whose value is to be queried
* @param columnIndex the column whose value is to be queried
* @return the value Object at the specified cell
*/
@Override
public Object getValueAt(int rowIndex, int columnIndex) {
switch (columnIndex) {
case 0:
return rowIndex;
case 1:
if (rowIndex == 0) {
return "";
}
return abc.constants.getMultiname(rowIndex).getKindStr();
case 2:
if (rowIndex == 0) {
return "";
}
if (abc.constants.getMultiname(rowIndex).name_index == -1) {
return "";
}
return abc.constants.getMultiname(rowIndex).getName(abc.constants, new ArrayList<String>(),true);
case 3:
if (rowIndex == 0) {
return "";
}
if (abc.constants.getMultiname(rowIndex).namespace_index <= 0) {
return "-";
}
return abc.constants.getMultiname(rowIndex).getNamespace(abc.constants).getNameWithKind(abc.constants);
case 4:
if (rowIndex == 0) {
return "";
}
if (abc.constants.getMultiname(rowIndex).namespace_set_index <= 0) {
return "-";
}
return abc.constants.getMultiname(rowIndex).getNamespaceSet(abc.constants).toString(abc.constants);
default:
return null;
}
}
/**
* Sets the value in the cell at <code>columnIndex</code> and
* <code>rowIndex</code> to <code>aValue</code>.
*
* @param aValue the new value
* @param rowIndex the row whose value is to be changed
* @param columnIndex the column whose value is to be changed
* @see #getValueAt
* @see #isCellEditable
*/
@Override
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
}
/**
* Adds a listener to the list that is notified each time a change to the
* data model occurs.
*
* @param l the TableModelListener
*/
@Override
public void addTableModelListener(TableModelListener l) {
}
/**
* Removes a listener from the list that is notified each time a change to
* the data model occurs.
*
* @param l the TableModelListener
*/
@Override
public void removeTableModelListener(TableModelListener l) {
}
}