mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-07-12 15:20:08 +00:00
better binary editor in generictagttreepanel
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -17,6 +17,7 @@
|
||||
package com.jpexs.decompiler.flash.gui;
|
||||
|
||||
import com.jpexs.decompiler.flash.SWF;
|
||||
import com.jpexs.decompiler.flash.gui.generictageditors.BinaryDataEditor;
|
||||
import com.jpexs.decompiler.flash.gui.generictageditors.BooleanEditor;
|
||||
import com.jpexs.decompiler.flash.gui.generictageditors.ColorEditor;
|
||||
import com.jpexs.decompiler.flash.gui.generictageditors.GenericTagEditor;
|
||||
@@ -39,7 +40,6 @@ import com.jpexs.decompiler.flash.types.annotations.parser.AnnotationParseExcept
|
||||
import com.jpexs.decompiler.flash.types.annotations.parser.ConditionEvaluator;
|
||||
import com.jpexs.helpers.ByteArrayRange;
|
||||
import com.jpexs.helpers.ConcreteClasses;
|
||||
import com.jpexs.helpers.Helper;
|
||||
import com.jpexs.helpers.ReflectionTools;
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
@@ -51,7 +51,6 @@ import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Array;
|
||||
import java.lang.reflect.Field;
|
||||
@@ -92,8 +91,6 @@ public class GenericTagTreePanel extends GenericTagPanel {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(GenericTagTreePanel.class.getName());
|
||||
|
||||
private final MainPanel mainPanel;
|
||||
|
||||
private JTree tree;
|
||||
|
||||
private Tag editedTag;
|
||||
@@ -166,6 +163,8 @@ public class GenericTagTreePanel extends GenericTagPanel {
|
||||
editor = new StringEditor(field.getName(), obj, field, index, type, multiline != null);
|
||||
} else if (type.equals(RGB.class) || type.equals(RGBA.class) || type.equals(ARGB.class)) {
|
||||
editor = new ColorEditor(field.getName(), obj, field, index, type);
|
||||
} else if (type.equals(ByteArrayRange.class)) {
|
||||
editor = new BinaryDataEditor(mainPanel, field.getName(), obj, field, index, type);
|
||||
}
|
||||
if (editor != null) {
|
||||
if (editors == null) {
|
||||
@@ -195,10 +194,6 @@ public class GenericTagTreePanel extends GenericTagPanel {
|
||||
pan.add(nameLabel);
|
||||
|
||||
JComponent editorComponent = (JComponent) editor;
|
||||
if (editorComponent == null && type.equals(ByteArrayRange.class)) {
|
||||
//ByteArrayRange bar = (ByteArrayRange) field.get(obj);
|
||||
nameLabel.setText(nameLabel.getText() + " ...");
|
||||
}
|
||||
if (editorComponent != null) {
|
||||
nameLabel.setSize(nameLabel.getWidth(), editorComponent.getHeight());
|
||||
editorComponent.setAlignmentY(TOP_ALIGNMENT);
|
||||
@@ -269,8 +264,8 @@ public class GenericTagTreePanel extends GenericTagPanel {
|
||||
}
|
||||
|
||||
public GenericTagTreePanel(MainPanel mainPanel) {
|
||||
super(mainPanel);
|
||||
setLayout(new BorderLayout());
|
||||
this.mainPanel = mainPanel;
|
||||
tree = new MyTree();
|
||||
|
||||
add(new JScrollPane(tree), BorderLayout.CENTER);
|
||||
@@ -289,18 +284,7 @@ public class GenericTagTreePanel extends GenericTagPanel {
|
||||
if (selObject instanceof FieldNode) {
|
||||
final FieldNode fnode = (FieldNode) selObject;
|
||||
Field field = fnode.fieldSet.get(FIELD_INDEX);
|
||||
if (field.getType().equals(ByteArrayRange.class)) {
|
||||
File selectedFile = mainPanel.showImportFileChooser("");
|
||||
if (selectedFile != null) {
|
||||
File selfile = Helper.fixDialogFile(selectedFile);
|
||||
byte[] data = Helper.readFile(selfile.getAbsolutePath());
|
||||
try {
|
||||
field.set(fnode.obj, new ByteArrayRange(data));
|
||||
} catch (IllegalArgumentException | IllegalAccessException ex) {
|
||||
Logger.getLogger(GenericTagTreePanel.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
} else if (ReflectionTools.needsIndex(field)) {
|
||||
if (ReflectionTools.needsIndex(field)) {
|
||||
SWFArray swfArray = fnode.fieldSet.get(FIELD_INDEX).getAnnotation(SWFArray.class);
|
||||
|
||||
String itemStr = "";
|
||||
|
||||
@@ -0,0 +1,131 @@
|
||||
/*
|
||||
* Copyright (C) 2010-2015 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.generictageditors;
|
||||
|
||||
import com.jpexs.decompiler.flash.gui.AppStrings;
|
||||
import com.jpexs.decompiler.flash.gui.MainPanel;
|
||||
import com.jpexs.helpers.ByteArrayRange;
|
||||
import com.jpexs.helpers.Helper;
|
||||
import com.jpexs.helpers.ReflectionTools;
|
||||
import java.awt.Component;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Field;
|
||||
import javax.swing.JButton;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
public class BinaryDataEditor extends JButton implements GenericTagEditor {
|
||||
|
||||
private final MainPanel mainPanel;
|
||||
|
||||
private final Object obj;
|
||||
|
||||
private final Field field;
|
||||
|
||||
private final int index;
|
||||
|
||||
private final Class<?> type;
|
||||
|
||||
private final String fieldName;
|
||||
|
||||
private Object value;
|
||||
|
||||
public BinaryDataEditor(MainPanel mainPanel, String fieldName, Object obj, Field field, int index, Class<?> type) {
|
||||
super();
|
||||
this.mainPanel = mainPanel;
|
||||
this.obj = obj;
|
||||
this.field = field;
|
||||
this.index = index;
|
||||
this.type = type;
|
||||
this.fieldName = fieldName;
|
||||
setText(AppStrings.translate("button.replace"));
|
||||
addActionListener(this::buttonActionPerformed);
|
||||
|
||||
try {
|
||||
ByteArrayRange bar = (ByteArrayRange) ReflectionTools.getValue(obj, field, index);
|
||||
setToolTipText(bar.getLength() + " bytes");
|
||||
value = bar;
|
||||
} catch (IllegalArgumentException | IllegalAccessException ex) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonActionPerformed(ActionEvent evt) {
|
||||
File selectedFile = mainPanel.showImportFileChooser("");
|
||||
if (selectedFile != null) {
|
||||
File selfile = Helper.fixDialogFile(selectedFile);
|
||||
byte[] data = Helper.readFile(selfile.getAbsolutePath());
|
||||
setToolTipText(data.length + " bytes");
|
||||
value = new ByteArrayRange(data);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save() {
|
||||
try {
|
||||
ReflectionTools.setValue(obj, field, index, value);
|
||||
} catch (IllegalArgumentException | IllegalAccessException ex) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addChangeListener(final ChangeListener l) {
|
||||
final GenericTagEditor t = this;
|
||||
addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
l.change(t);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getChangedValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFieldName() {
|
||||
return fieldName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Field getField() {
|
||||
return field;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getReadOnlyValue() {
|
||||
return getChangedValue().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaselineResizeBehavior getBaselineResizeBehavior() {
|
||||
return Component.BaselineResizeBehavior.CONSTANT_ASCENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBaseline(int width, int height) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user