mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-06-01 07:45:07 +00:00
108 lines
4.2 KiB
Java
108 lines
4.2 KiB
Java
/*
|
|
* Copyright (C) 2011-2013 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.abc.ABC;
|
|
import com.jpexs.decompiler.flash.abc.methodinfo_parser.MethodInfoParser;
|
|
import com.jpexs.decompiler.flash.abc.methodinfo_parser.ParseException;
|
|
import com.jpexs.decompiler.flash.abc.types.ValueKind;
|
|
import com.jpexs.decompiler.flash.abc.types.traits.TraitSlotConst;
|
|
import static com.jpexs.decompiler.flash.gui.AppStrings.translate;
|
|
import com.jpexs.decompiler.flash.helpers.Helper;
|
|
import java.awt.BorderLayout;
|
|
import java.awt.Color;
|
|
import java.awt.Font;
|
|
import java.util.ArrayList;
|
|
import javax.swing.*;
|
|
import javax.swing.text.SimpleAttributeSet;
|
|
import javax.swing.text.StyleConstants;
|
|
import javax.swing.text.StyledDocument;
|
|
import jsyntaxpane.syntaxkits.Flasm3MethodInfoSyntaxKit;
|
|
|
|
/**
|
|
*
|
|
* @author JPEXS
|
|
*/
|
|
public class SlotConstTraitDetailPanel extends JPanel implements TraitDetail {
|
|
|
|
public JEditorPane slotConstEditor;
|
|
private ABC abc;
|
|
private TraitSlotConst trait;
|
|
private JTextPane warnLabel;
|
|
|
|
public SlotConstTraitDetailPanel() {
|
|
slotConstEditor = new JEditorPane();
|
|
setLayout(new BorderLayout());
|
|
add(new JLabel(translate("abc.detail.slotconst.typevalue")), BorderLayout.NORTH);
|
|
add(new JScrollPane(slotConstEditor), BorderLayout.CENTER);
|
|
warnLabel = new JTextPane();
|
|
warnLabel.setText(translate("warning.initializers"));
|
|
StyledDocument doc = warnLabel.getStyledDocument();
|
|
SimpleAttributeSet center = new SimpleAttributeSet();
|
|
StyleConstants.setAlignment(center, StyleConstants.ALIGN_CENTER);
|
|
doc.setParagraphAttributes(0, doc.getLength(), center, false);
|
|
warnLabel.setOpaque(false);
|
|
warnLabel.setFocusable(false);
|
|
//warnLabel.setWrapStyleWord(true);
|
|
//warnLabel.setLineWrap(true);
|
|
warnLabel.setFont(new JLabel().getFont().deriveFont(Font.BOLD));
|
|
add(warnLabel, BorderLayout.SOUTH);
|
|
slotConstEditor.setContentType("text/flasm3_methodinfo");
|
|
Flasm3MethodInfoSyntaxKit sk = (Flasm3MethodInfoSyntaxKit) slotConstEditor.getEditorKit();
|
|
sk.deinstallComponent(slotConstEditor, "jsyntaxpane.components.LineNumbersRuler");
|
|
}
|
|
|
|
public void load(TraitSlotConst trait, ABC abc, boolean isStatic) {
|
|
this.abc = abc;
|
|
this.trait = trait;
|
|
String s;
|
|
String typeStr;
|
|
if (trait.type_index > 0) {
|
|
typeStr = "m[" + trait.type_index + "]\"" + Helper.escapeString(abc.constants.constant_multiname[trait.type_index].toString(abc.constants, new ArrayList<String>())) + "\"";
|
|
} else {
|
|
typeStr = "*";
|
|
}
|
|
String valueStr = "";
|
|
if (trait.value_kind != 0) {
|
|
valueStr = " = " + (new ValueKind(trait.value_index, trait.value_kind)).toString(abc.constants);
|
|
}
|
|
|
|
s = typeStr + valueStr;
|
|
|
|
warnLabel.setVisible(trait.isConst() || isStatic);
|
|
slotConstEditor.setText(s);
|
|
}
|
|
|
|
@Override
|
|
public boolean save() {
|
|
try {
|
|
if (!MethodInfoParser.parseSlotConst(slotConstEditor.getText(), trait, abc)) {
|
|
return false;
|
|
}
|
|
} catch (ParseException ex) {
|
|
JOptionPane.showMessageDialog(slotConstEditor, ex.text, translate("error.slotconst.typevalue"), JOptionPane.ERROR_MESSAGE);
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public void setEditMode(boolean val) {
|
|
slotConstEditor.setEditable(val);
|
|
}
|
|
}
|