Added Exporting ByteArrayRange in the raw editor with the Export button

This commit is contained in:
Jindra Petřík
2023-09-23 20:00:01 +02:00
parent 302c909566
commit 314cc5bd61
4 changed files with 50 additions and 7 deletions

View File

@@ -16,26 +16,41 @@
*/
package com.jpexs.decompiler.flash.gui.generictageditors;
import com.jpexs.decompiler.flash.configuration.Configuration;
import com.jpexs.decompiler.flash.gui.AppStrings;
import com.jpexs.decompiler.flash.gui.MainPanel;
import com.jpexs.decompiler.flash.gui.ViewMessages;
import com.jpexs.helpers.ByteArrayRange;
import com.jpexs.helpers.Helper;
import com.jpexs.helpers.ReflectionTools;
import java.awt.Component;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.Objects;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
/**
*
* @author JPEXS
*/
public class BinaryDataEditor extends JButton implements GenericTagEditor {
public class BinaryDataEditor extends JPanel implements GenericTagEditor {
private final MainPanel mainPanel;
private final JButton replaceButton;
private final JButton exportButton;
private final Object obj;
@@ -57,8 +72,14 @@ public class BinaryDataEditor extends JButton implements GenericTagEditor {
this.index = index;
this.type = type;
this.fieldName = fieldName;
setText(AppStrings.translate("button.replace"));
addActionListener(this::buttonActionPerformed);
exportButton = new JButton(AppStrings.translate("button.export"));
replaceButton = new JButton(AppStrings.translate("button.replace"));
setLayout(new FlowLayout());
add(exportButton);
add(replaceButton);
exportButton.addActionListener(this::exportActionPerformed);
replaceButton.addActionListener(this::replaceActionPerformed);
reset();
}
@@ -84,7 +105,24 @@ public class BinaryDataEditor extends JButton implements GenericTagEditor {
}
}
private void buttonActionPerformed(ActionEvent evt) {
private void exportActionPerformed(ActionEvent evt) {
if (value == null) {
return;
}
JFileChooser fc = new JFileChooser();
fc.setCurrentDirectory(new File(Configuration.lastExportDir.get()));
if (fc.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
File selfile = Helper.fixDialogFile(fc.getSelectedFile());
ByteArrayRange br = (ByteArrayRange)value;
try(FileOutputStream fos = new FileOutputStream(selfile)) {
fos.write(br.getArray(), br.getPos(), br.getLength());
} catch (IOException ex) {
ViewMessages.showMessageDialog(mainPanel, ex.getMessage(), AppStrings.translate("error"), JOptionPane.ERROR_MESSAGE);
}
}
}
private void replaceActionPerformed(ActionEvent evt) {
File selectedFile = mainPanel.showImportFileChooser("", false);
if (selectedFile != null) {
File selfile = Helper.fixDialogFile(selectedFile);
@@ -117,7 +155,7 @@ public class BinaryDataEditor extends JButton implements GenericTagEditor {
@Override
public void addChangeListener(final ChangeListener l) {
final GenericTagEditor t = this;
addActionListener(new ActionListener() {
replaceButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {

View File

@@ -1145,4 +1145,6 @@ warning.edit.headerframecount = WARNING: Editing frame count in the header does
neccessary number of ShowFrame tags on SWF timeline.\r\nTo add new frames, you should better use right click context menu on SWF -> Add frames,\r\n\
which will update the frame count in the header accordingly.
warning.icon = Click to show related warning
warning.icon = Click to show related warning
button.export = Export

View File

@@ -1130,4 +1130,6 @@ warning.edit.headerframecount = VAROV\u00c1N\u00cd: Editace po\u010dtu sn\u00edm
pot\u0159ebn\u00fd po\u010det ShowFrame tag\u016f na SWF \u010dasov\u00e9 ose.\r\nPro p\u0159id\u00e1n\u00ed nov\u00fdch sn\u00edmk\u016f byste m\u011bl rad\u011bji pou\u017e\u00edt kontextov\u00e9 menu o prav\u00e9m kliknu na SWF -> P\u0159idat sn\u00edmky,\r\n\
co\u017e aktualizuje podle toho i po\u010det sn\u00edmk\u016f v hlavi\u010dce.
warning.icon = Klikn\u011bte pro zobrazen\u00ed souvisej\u00edc\u00edho varov\u00e1n\u00ed
warning.icon = Klikn\u011bte pro zobrazen\u00ed souvisej\u00edc\u00edho varov\u00e1n\u00ed
button.export = Exportovat