From 2befbcb65d6ccefa2e7ea43798b7ab0e6dc72621 Mon Sep 17 00:00:00 2001 From: "honfika@gmail.com" Date: Thu, 26 Feb 2015 23:56:48 +0100 Subject: [PATCH] #805 Autosave --- .../com/jpexs/decompiler/flash/BigObject.java | 32 +++++ .../src/com/jpexs/decompiler/flash/SWF.java | 2 + .../flash/configuration/Configuration.java | 4 + .../flash/tags/DefineEditTextTag.java | 4 + .../decompiler/flash/tags/DefineText2Tag.java | 8 +- .../decompiler/flash/tags/DefineTextTag.java | 8 +- .../decompiler/flash/tags/base/TextTag.java | 4 +- .../decompiler/flash/gui/ImagePanel.java | 6 + .../jpexs/decompiler/flash/gui/MainPanel.java | 6 + .../decompiler/flash/gui/PreviewPanel.java | 8 +- .../jpexs/decompiler/flash/gui/TextPanel.java | 111 ++++++++---------- .../flash/gui/dumpview/DumpTree.java | 16 ++- .../locales/AdvancedSettingsDialog.properties | 3 + .../AdvancedSettingsDialog_hu.properties | 3 + .../decompiler/flash/gui/tagtree/TagTree.java | 16 ++- 15 files changed, 147 insertions(+), 84 deletions(-) create mode 100644 libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/BigObject.java diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/BigObject.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/BigObject.java new file mode 100644 index 000000000..9fd2f3017 --- /dev/null +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/BigObject.java @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2010-2015 JPEXS, All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3.0 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. + */ +package com.jpexs.decompiler.flash; + +/** + * + * @author JPEXS + */ +public class BigObject { + + private byte[] dummy = new byte[512 * 1024 * 1024]; + + @Override + protected void finalize() throws Throwable { + super.finalize(); + System.out.println("swf finalized"); + } +} diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java index 5b1f6c586..d510f530a 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java @@ -182,6 +182,8 @@ import org.monte.media.avi.AVIWriter; */ public final class SWF implements SWFContainerItem, Timelined { + // big object for testing cleanup + //BigObject bigObj = new BigObject(); /** * Default version of SWF file format */ diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/configuration/Configuration.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/configuration/Configuration.java index 69d3a2ac3..bf02eca75 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/configuration/Configuration.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/configuration/Configuration.java @@ -409,6 +409,10 @@ public class Configuration { @ConfigurationCategory("ui") public static final ConfigurationItem editorMode = null; + @ConfigurationDefaultBoolean(false) + @ConfigurationCategory("ui") + public static final ConfigurationItem autoSaveTagModifications = null; + private enum OSId { WINDOWS, OSX, UNIX diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineEditTextTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineEditTextTag.java index 7b64fa060..3d4356cb9 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineEditTextTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineEditTextTag.java @@ -660,6 +660,10 @@ public class DefineEditTextTag extends TextTag { return true; } + @Override + public void updateTextBounds() { + } + @Override public boolean alignText(TextAlign textAlign) { return true; diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineText2Tag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineText2Tag.java index f1942ff91..c89ab1489 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineText2Tag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineText2Tag.java @@ -436,10 +436,15 @@ public class DefineText2Tag extends TextTag { throw ex; } - updateTextBounds(textBounds); + updateTextBounds(); return true; } + @Override + public void updateTextBounds() { + updateTextBounds(textBounds); + } + @Override public boolean alignText(TextAlign textAlign) { alignText(swf, textRecords, textAlign); @@ -450,6 +455,7 @@ public class DefineText2Tag extends TextTag { @Override public boolean translateText(int diff) { textMatrix.translateX += diff; + updateTextBounds(); setModified(true); return true; } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineTextTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineTextTag.java index 0b0da95f8..eec2b4fe3 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineTextTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineTextTag.java @@ -444,10 +444,15 @@ public class DefineTextTag extends TextTag { throw ex; } - updateTextBounds(textBounds); + updateTextBounds(); return true; } + @Override + public void updateTextBounds() { + updateTextBounds(textBounds); + } + @Override public boolean alignText(TextAlign textAlign) { alignText(swf, textRecords, textAlign); @@ -458,6 +463,7 @@ public class DefineTextTag extends TextTag { @Override public boolean translateText(int diff) { textMatrix.translateX += diff; + updateTextBounds(); setModified(true); return true; } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/base/TextTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/base/TextTag.java index 57449092b..24f60b1d7 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/base/TextTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/base/TextTag.java @@ -85,6 +85,8 @@ public abstract class TextTag extends CharacterTag implements DrawableTag { // use the texts from the "texts" argument when it is not null public abstract boolean setFormattedText(MissingCharacterHandler missingCharHandler, String formattedText, String[] texts) throws TextParseException; + public abstract void updateTextBounds(); + public abstract boolean alignText(TextAlign textAlign); public abstract boolean translateText(int diff); @@ -500,7 +502,7 @@ public abstract class TextTag extends CharacterTag implements DrawableTag { return result; } - public void updateTextBounds(RECT textBounds) { + protected void updateTextBounds(RECT textBounds) { TextImportResizeTextBoundsMode resizeMode = Configuration.textImportResizeTextBoundsMode.get(); if (resizeMode != null && (resizeMode.equals(TextImportResizeTextBoundsMode.GROW_ONLY) || resizeMode.equals(TextImportResizeTextBoundsMode.GROW_AND_SHRINK))) { ExportRectangle newBounds = calculateTextBounds(); diff --git a/src/com/jpexs/decompiler/flash/gui/ImagePanel.java b/src/com/jpexs/decompiler/flash/gui/ImagePanel.java index 0a49cb2fa..481eda4c7 100644 --- a/src/com/jpexs/decompiler/flash/gui/ImagePanel.java +++ b/src/com/jpexs/decompiler/flash/gui/ImagePanel.java @@ -853,6 +853,12 @@ public final class ImagePanel extends JPanel implements ActionListener, MediaDis return outlines; } + public synchronized void clearAll() { + stop(); + timelined = null; + swf = null; + } + public synchronized void stop() { clear(); stopAllSounds(); diff --git a/src/com/jpexs/decompiler/flash/gui/MainPanel.java b/src/com/jpexs/decompiler/flash/gui/MainPanel.java index 3791c1396..60faffabf 100644 --- a/src/com/jpexs/decompiler/flash/gui/MainPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/MainPanel.java @@ -2377,7 +2377,13 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec } + private void closeTag() { + previewPanel.closeTag(); + } + public void reload(boolean forceReload) { + closeTag(); + if (Configuration.dumpView.get()) { dumpViewReload(forceReload); return; diff --git a/src/com/jpexs/decompiler/flash/gui/PreviewPanel.java b/src/com/jpexs/decompiler/flash/gui/PreviewPanel.java index a178dda8c..066ee13b8 100644 --- a/src/com/jpexs/decompiler/flash/gui/PreviewPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/PreviewPanel.java @@ -455,11 +455,11 @@ public class PreviewPanel extends JSplitPane implements ActionListener { showCardRight(CARDTEXTPANEL); parametersPanel.setVisible(true); setDividerLocation(Configuration.guiPreviewSplitPaneDividerLocation.get(getWidth() / 2)); - textPanel.setText(textTag.getFormattedText()); + textPanel.setText(textTag); } public void clear() { - imagePanel.stop(); + imagePanel.clearAll(); if (media != null) { media.pause(); } @@ -469,6 +469,10 @@ public class PreviewPanel extends JSplitPane implements ActionListener { fontPanel.clear(); } + public void closeTag() { + textPanel.closeTag(); + } + public void showBinaryPanel(DefineBinaryDataTag binaryDataTag) { showCardLeft(BINARY_TAG_CARD); binaryPanel.setBinaryData(binaryDataTag); diff --git a/src/com/jpexs/decompiler/flash/gui/TextPanel.java b/src/com/jpexs/decompiler/flash/gui/TextPanel.java index 409e5560c..5b0d5fab1 100644 --- a/src/com/jpexs/decompiler/flash/gui/TextPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/TextPanel.java @@ -20,13 +20,11 @@ import com.jpexs.decompiler.flash.SWF; import com.jpexs.decompiler.flash.configuration.Configuration; import com.jpexs.decompiler.flash.gui.abc.LineMarkedEditorPane; import com.jpexs.decompiler.flash.tags.DefineEditTextTag; -import com.jpexs.decompiler.flash.tags.Tag; import com.jpexs.decompiler.flash.tags.base.FontTag; import com.jpexs.decompiler.flash.tags.base.MissingCharacterHandler; import com.jpexs.decompiler.flash.tags.base.TextTag; import com.jpexs.decompiler.flash.tags.text.TextAlign; import com.jpexs.decompiler.flash.tags.text.TextParseException; -import com.jpexs.decompiler.flash.treeitems.TreeItem; import java.awt.BorderLayout; import java.awt.FlowLayout; import java.awt.Font; @@ -76,6 +74,8 @@ public class TextPanel extends JPanel { private final JButton undoChangesButton; + private TextTag textTag; + private boolean modified = false; public TextPanel(final MainPanel mainPanel) { @@ -160,13 +160,22 @@ public class TextPanel extends JPanel { return textSearchPanel; } - public void setText(String text) { - textValue.setText(text); + public void setText(TextTag textTag) { + this.textTag = textTag; + textValue.setText(textTag.getFormattedText()); textValue.setCaretPosition(0); modified = false; setEditText(false); } + public void closeTag() { + if (modified && Configuration.autoSaveTagModifications.get()) { + saveText(); + } + + textTag = null; + } + private void setEditText(boolean edit) { textValue.setEditable(Configuration.editorMode.get() || edit); updateButtonsVisibility(); @@ -181,9 +190,8 @@ public class TextPanel extends JPanel { textCancelButton.setVisible(edit); textCancelButton.setEnabled(modified || !editorMode); - TreeItem item = mainPanel.tagTree.getCurrentTreeItem(); boolean alignable = false; - if (item instanceof TextTag && !(item instanceof DefineEditTextTag)) { + if (textTag != null && !(textTag instanceof DefineEditTextTag)) { alignable = !edit || (editorMode && !modified); } @@ -194,7 +202,7 @@ public class TextPanel extends JPanel { increaseTranslateXButton.setVisible(alignable); decreaseTranslateXButton.setVisible(alignable); - undoChangesButton.setVisible(item != null && item instanceof TextTag && ((Tag) item).isModified()); + undoChangesButton.setVisible(textTag != null && textTag.isModified()); } public void updateSearchPos() { @@ -219,54 +227,39 @@ public class TextPanel extends JPanel { } private void saveText() { - TreeItem item = mainPanel.tagTree.getCurrentTreeItem(); - if (item instanceof TextTag) { - TextTag textTag = (TextTag) item; - if (mainPanel.saveText(textTag, textValue.getText(), null)) { - setEditText(false); - modified = false; - item.getSwf().clearImageCache(); - mainPanel.refreshTree(); - } + if (mainPanel.saveText(textTag, textValue.getText(), null)) { + setEditText(false); + modified = false; + textTag.getSwf().clearImageCache(); + mainPanel.refreshTree(); } } private void textAlign(TextAlign textAlign) { - TreeItem item = mainPanel.tagTree.getCurrentTreeItem(); - if (item instanceof TextTag) { - TextTag textTag = (TextTag) item; - if (mainPanel.alignText(textTag, textAlign)) { - updateButtonsVisibility(); - item.getSwf().clearImageCache(); - mainPanel.refreshTree(); - } + if (mainPanel.alignText(textTag, textAlign)) { + updateButtonsVisibility(); + textTag.getSwf().clearImageCache(); + mainPanel.refreshTree(); } } private void translateX(int delta) { - TreeItem item = mainPanel.tagTree.getCurrentTreeItem(); - if (item instanceof TextTag) { - TextTag textTag = (TextTag) item; - if (mainPanel.translateText(textTag, delta)) { - updateButtonsVisibility(); - item.getSwf().clearImageCache(); - mainPanel.refreshTree(); - } + if (mainPanel.translateText(textTag, delta)) { + updateButtonsVisibility(); + textTag.getSwf().clearImageCache(); + mainPanel.refreshTree(); } } private void undoChanges() { - TreeItem item = mainPanel.tagTree.getCurrentTreeItem(); - if (item instanceof TextTag) { - try { - ((Tag) item).undo(); - } catch (InterruptedException | IOException ex) { - Logger.getLogger(TextPanel.class.getName()).log(Level.SEVERE, null, ex); - } - - item.getSwf().clearImageCache(); - mainPanel.refreshTree(); + try { + textTag.undo(); + } catch (InterruptedException | IOException ex) { + Logger.getLogger(TextPanel.class.getName()).log(Level.SEVERE, null, ex); } + + textTag.getSwf().clearImageCache(); + mainPanel.refreshTree(); } private void textChanged() { @@ -282,29 +275,25 @@ public class TextPanel extends JPanel { } if (textValue.isEditable()) { - TreeItem item = mainPanel.tagTree.getCurrentTreeItem(); - if (item instanceof TextTag) { - TextTag textTag = (TextTag) item; - boolean ok = false; - try { - TextTag copyTextTag = (TextTag) textTag.cloneTag(); - if (copyTextTag.setFormattedText(new MissingCharacterHandler() { + boolean ok = false; + try { + TextTag copyTextTag = (TextTag) textTag.cloneTag(); + if (copyTextTag.setFormattedText(new MissingCharacterHandler() { - @Override - public boolean handle(TextTag textTag, FontTag font, char character) { - return false; - } - - }, textValue.getText(), null)) { - ok = true; - mainPanel.showTextTagWithNewValue(textTag, copyTextTag); + @Override + public boolean handle(TextTag textTag, FontTag font, char character) { + return false; } - } catch (TextParseException | InterruptedException | IOException ex) { - } - if (!ok) { - mainPanel.showTextTagWithNewValue(textTag, null); + }, textValue.getText(), null)) { + ok = true; + mainPanel.showTextTagWithNewValue(textTag, copyTextTag); } + } catch (TextParseException | InterruptedException | IOException ex) { + } + + if (!ok) { + mainPanel.showTextTagWithNewValue(textTag, null); } } } diff --git a/src/com/jpexs/decompiler/flash/gui/dumpview/DumpTree.java b/src/com/jpexs/decompiler/flash/gui/dumpview/DumpTree.java index 6cbb56dad..5381dbfca 100644 --- a/src/com/jpexs/decompiler/flash/gui/dumpview/DumpTree.java +++ b/src/com/jpexs/decompiler/flash/gui/dumpview/DumpTree.java @@ -33,7 +33,6 @@ import com.jpexs.decompiler.flash.gui.View; import com.jpexs.helpers.Helper; import com.jpexs.helpers.MemoryInputStream; import java.awt.Color; -import java.awt.Graphics; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseAdapter; @@ -44,7 +43,6 @@ import java.io.IOException; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; -import javax.swing.JComponent; import javax.swing.JFileChooser; import javax.swing.JFrame; import javax.swing.JMenuItem; @@ -92,13 +90,6 @@ public class DumpTree extends JTree implements ActionListener { setCellRenderer(new DumpTreeCellRenderer()); setRootVisible(false); setBackground(Color.white); - setUI(new BasicTreeUI() { - @Override - public void paint(Graphics g, JComponent c) { - setHashColor(Color.gray); - super.paint(g, c); - } - }); } public void createContextMenu() { @@ -293,6 +284,13 @@ public class DumpTree extends JTree implements ActionListener { @Override public void setModel(TreeModel tm) { super.setModel(tm); + + setUI(new BasicTreeUI() { + { + setHashColor(Color.gray); + } + }); + if (tm != null) { int rowCount = tm.getChildCount(tm.getRoot()); for (int i = rowCount - 1; i >= 0; i--) { diff --git a/src/com/jpexs/decompiler/flash/gui/locales/AdvancedSettingsDialog.properties b/src/com/jpexs/decompiler/flash/gui/locales/AdvancedSettingsDialog.properties index 38934fe6c..cc0c34490 100644 --- a/src/com/jpexs/decompiler/flash/gui/locales/AdvancedSettingsDialog.properties +++ b/src/com/jpexs/decompiler/flash/gui/locales/AdvancedSettingsDialog.properties @@ -320,3 +320,6 @@ config.description.updateProxyAddress = Http Proxy address for checking updates. config.name.editorMode = Editor Mode config.description.editorMode = Make text areas edittable automatically when you select a Text or Script node + +config.name.autoSaveTagModifications = Auto save tag modificatios +config.description.autoSaveTagModifications = Save the changes when you select a new tag in the tree diff --git a/src/com/jpexs/decompiler/flash/gui/locales/AdvancedSettingsDialog_hu.properties b/src/com/jpexs/decompiler/flash/gui/locales/AdvancedSettingsDialog_hu.properties index d3aab00d1..ceb8b3053 100644 --- a/src/com/jpexs/decompiler/flash/gui/locales/AdvancedSettingsDialog_hu.properties +++ b/src/com/jpexs/decompiler/flash/gui/locales/AdvancedSettingsDialog_hu.properties @@ -317,3 +317,6 @@ config.description.showTraitSavedMessage = Trait mentve \u00fczenet \u00fajra mu config.name.updateProxyAddress = Http Proxy c\u00edm a friss\u00edt\u00e9sek keres\u00e9s\u00e9hez config.description.updateProxyAddress = Http Proxy c\u00edm a friss\u00edt\u00e9sek keres\u00e9s\u00e9hez. Form\u00e1tum: example.com:8080 + +config.name.autoSaveTagModifications = Tag m\u00f3dos\u00edt\u00e1sainak automatikus ment\u00e9se +config.description.autoSaveTagModifications = V\u00e1ltoz\u00e1sok ment\u00e9se amikor \u00faj tag-et v\u00e1laszt ki a f\u00e1ban diff --git a/src/com/jpexs/decompiler/flash/gui/tagtree/TagTree.java b/src/com/jpexs/decompiler/flash/gui/tagtree/TagTree.java index 44129cdba..750622c25 100644 --- a/src/com/jpexs/decompiler/flash/gui/tagtree/TagTree.java +++ b/src/com/jpexs/decompiler/flash/gui/tagtree/TagTree.java @@ -119,7 +119,6 @@ import java.util.List; import java.util.Map; import javax.swing.Icon; import javax.swing.JTree; -import javax.swing.plaf.TreeUI; import javax.swing.plaf.basic.BasicLabelUI; import javax.swing.plaf.basic.BasicTreeUI; import javax.swing.tree.DefaultTreeCellRenderer; @@ -218,14 +217,6 @@ public class TagTree extends JTree { setBackground(Color.white); setRowHeight(16); setLargeModel(true); - - TreeUI treeUI = new BasicTreeUI() { - { - setHashColor(Color.gray); - } - }; - - setUI(treeUI); } public void createContextMenu() { @@ -545,6 +536,13 @@ public class TagTree extends JTree { @Override public void setModel(TreeModel tm) { super.setModel(tm); + + setUI(new BasicTreeUI() { + { + setHashColor(Color.gray); + } + }); + if (tm != null) { int rowCount = tm.getChildCount(tm.getRoot()); for (int i = rowCount - 1; i >= 0; i--) {