From 1cf0c28c7485c6cfc5c4fc17c5b7019afbc40f8a Mon Sep 17 00:00:00 2001 From: "honfika@gmail.com" Date: Sun, 23 Nov 2014 22:54:19 +0100 Subject: [PATCH] #676: extended logging for text import, imorpt logic moved to separated class, allow to ignore errors duting import --- .../flash/IdentifiersDeobfuscation.java | 17 +- .../src/com/jpexs/decompiler/flash/SWF.java | 30 +-- .../abc/avm2/parser/pcode/Flasm3Lexer.java | 2 +- .../parser/script/AVM2SourceGenerator.java | 8 +- .../avm2/parser/script/ActionScriptLexer.java | 2 +- .../parser/script/ActionScriptParser.java | 4 +- .../abc/avm2/parser/script/NameAVM2Item.java | 9 +- .../avm2/parser/script/PropertyAVM2Item.java | 2 +- .../parser/script/UnresolvedAVM2Item.java | 2 +- .../methodinfo_parser/MethodInfoLexer.java | 2 +- .../flash/abc/types/MethodInfo.java | 2 +- .../flash/action/parser/pcode/FlasmLexer.java | 2 +- .../parser/script/ActionScriptLexer.java | 2 +- .../flash/exporters/ImageExporter.java | 34 ++-- .../flash/exporters/ShapeExporter.java | 4 +- .../flash/exporters/commonshape/Matrix.java | 16 +- .../morphshape/MorphShapeExporterBase.java | 4 +- .../exporters/shape/ShapeExporterBase.java | 4 +- .../decompiler/flash/helpers/BMPFile.java | 8 +- .../flash/helpers/hilight/HighlightData.java | 12 +- .../helpers/hilight/HighlightSpecialType.java | 4 +- .../flash/helpers/hilight/Highlighting.java | 4 +- .../flash/importers/ShapeImporter.java | 16 +- .../flash/importers/TextImporter.java | 183 +++++++++++++++++ .../flash/tags/DefineBitsJPEG3Tag.java | 2 +- .../flash/tags/DefineButton2Tag.java | 2 +- .../flash/tags/DefineButtonTag.java | 2 +- .../flash/tags/DefineEditTextTag.java | 31 +-- .../flash/tags/DefineSpriteTag.java | 2 +- .../decompiler/flash/tags/DefineText2Tag.java | 54 ++--- .../decompiler/flash/tags/DefineTextTag.java | 43 ++-- .../flash/tags/PlaceObject2Tag.java | 6 +- .../flash/tags/PlaceObject3Tag.java | 6 +- .../flash/tags/PlaceObject4Tag.java | 6 +- .../decompiler/flash/tags/PlaceObjectTag.java | 7 +- .../flash/tags/TagChangedListener.java | 2 +- .../decompiler/flash/tags/base/ImageTag.java | 6 +- .../flash/tags/base/PlaceObjectTypeTag.java | 4 +- .../tags/base/TextImportErrorHandler.java | 28 +++ .../decompiler/flash/tags/text/TextLexer.java | 2 +- .../flash/types/ColorTransform.java | 2 +- .../jpexs/decompiler/flash/types/MATRIX.java | 4 +- .../annotations/parser/ConditionLexer.java | 2 +- .../decompiler/flash/types/gfx/EdgeType.java | 2 +- .../decompiler/flash/xfl/XFLConverter.java | 12 +- .../src/com/jpexs/helpers/Cache.java | 18 +- .../src/com/jpexs/helpers/FileHashMap.java | 39 ++-- .../src/com/jpexs/helpers/Helper.java | 9 +- .../src/com/jpexs/helpers/Searchable.java | 9 +- .../src/com/jpexs/helpers/StreamSearch.java | 6 +- .../jpexs/helpers/SwfHeaderStreamSearch.java | 8 +- .../src/com/jpexs/helpers/resource/canvas.js | 106 +++++----- .../jpexs/decompiler/flash/RecompileTest.java | 3 +- .../flash/gui/FolderPreviewPanel.java | 2 +- .../decompiler/flash/gui/ImagePanel.java | 2 +- .../jpexs/decompiler/flash/gui/MainPanel.java | 191 +++++------------- .../decompiler/flash/gui/PreviewPanel.java | 16 +- src/com/jpexs/decompiler/flash/gui/View.java | 4 + .../flash/gui/locales/MainFrame.properties | 4 +- .../flash/gui/player/FlashPlayerPanel.java | 8 +- .../flash/gui/player/PlayerControls.java | 22 +- 61 files changed, 573 insertions(+), 472 deletions(-) create mode 100644 libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/TextImporter.java create mode 100644 libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/base/TextImportErrorHandler.java diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/IdentifiersDeobfuscation.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/IdentifiersDeobfuscation.java index 731347fe2..dcc9796f4 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/IdentifiersDeobfuscation.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/IdentifiersDeobfuscation.java @@ -289,8 +289,8 @@ public class IdentifiersDeobfuscation { return "\u00A7" + escapeOIdentifier(s) + "\u00A7"; } - private static final Cache as3NameCache = Cache.getInstance(false,"as3_ident"); - private static final Cache as2NameCache = Cache.getInstance(false,"as2_ident"); + private static final Cache as3NameCache = Cache.getInstance(false, "as3_ident"); + private static final Cache as2NameCache = Cache.getInstance(false, "as2_ident"); /** * Ensures identifier is valid and if not, uses paragraph syntax @@ -305,19 +305,18 @@ public class IdentifiersDeobfuscation { if (s.startsWith("\u00A7") && s.endsWith("\u00A7")) { //Assuming already printed - TODO:detect better return s; } - + for (String e : validExceptions) { if (e.equals(s)) { return s; } - } - Cache nameCache = as3?as3NameCache:as2NameCache; - - + } + Cache nameCache = as3 ? as3NameCache : as2NameCache; + if (nameCache.contains(s)) { return nameCache.get(s); } - + if (isValidName(as3, s, validExceptions)) { nameCache.put(s, s); return s; @@ -328,7 +327,7 @@ public class IdentifiersDeobfuscation { } public static String printNamespace(boolean as3, String pkg, String... validNameExceptions) { - Cache nameCache = as3?as3NameCache:as2NameCache; + Cache nameCache = as3 ? as3NameCache : as2NameCache; if (nameCache.contains(pkg)) { return nameCache.get(pkg); } 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 c86688e98..c34b4c9c9 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java @@ -278,9 +278,9 @@ public final class SWF implements SWFContainerItem, Timelined { public DumpInfoSwfNode dumpInfo; public DefineBinaryDataTag binaryData; - private static Cache frameCache = Cache.getInstance(false,"frame"); - private final Cache as2Cache = Cache.getInstance(true,"as2"); - private final Cache as3Cache = Cache.getInstance(true,"as3"); + private static Cache frameCache = Cache.getInstance(false, "frame"); + private final Cache as2Cache = Cache.getInstance(true, "as2"); + private final Cache as3Cache = Cache.getInstance(true, "as3"); public void updateCharacters() { characters.clear(); @@ -307,10 +307,10 @@ public final class SWF implements SWFContainerItem, Timelined { } } } - + return jtt; } - + public void fixCharactersOrder(boolean checkAll) { Set addedCharacterIds = new HashSet<>(); Set movedTags = new HashSet<>(); @@ -326,7 +326,7 @@ public final class SWF implements SWFContainerItem, Timelined { if (neededCharacter == null) { continue; } - + if (movedTags.contains(neededCharacter)) { logger.log(Level.SEVERE, "Fixing characters order failed, recursion detected."); return; @@ -648,13 +648,13 @@ public final class SWF implements SWFContainerItem, Timelined { throw new IOException("Invalid SWF file. No known tag found."); } } - + /* preload shape tags - for (Tag tag : tags) { - if (tag instanceof ShapeTag) { - ((ShapeTag) tag).getShapes(); - } - }*/ + for (Tag tag : tags) { + if (tag instanceof ShapeTag) { + ((ShapeTag) tag).getShapes(); + } + }*/ } @Override @@ -2136,14 +2136,14 @@ public final class SWF implements SWFContainerItem, Timelined { as2Cache.clear(); as3Cache.clear(); } - + public void clearAllCache() { clearImageCache(); clearScriptCache(); Cache.clearAll(); System.gc(); } - + public static void uncache(ASMSource src) { if (src != null) { src.getSwf().as2Cache.remove(src); @@ -2169,7 +2169,7 @@ public final class SWF implements SWFContainerItem, Timelined { if (swf.as2Cache.contains(src)) { return swf.as2Cache.get(src); } - + if (actions == null) { actions = src.getActions(); } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/pcode/Flasm3Lexer.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/pcode/Flasm3Lexer.java index f26cb2014..a51456dee 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/pcode/Flasm3Lexer.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/pcode/Flasm3Lexer.java @@ -2978,7 +2978,7 @@ public final class Flasm3Lexer { zzInput = zzBufferL[zzCurrentPosL++]; } } - int zzNext = zzTransL[ zzRowMapL[zzState] + zzCMapL[zzInput]]; + int zzNext = zzTransL[zzRowMapL[zzState] + zzCMapL[zzInput]]; if (zzNext == -1) { break zzForAction; } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/AVM2SourceGenerator.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/AVM2SourceGenerator.java index ede2508d8..99e8ea353 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/AVM2SourceGenerator.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/AVM2SourceGenerator.java @@ -1308,7 +1308,7 @@ public class AVM2SourceGenerator implements SourceGenerator { if (type instanceof UnboundedTypeItem) { return 0; } - if((""+type).equals("*")){ + if (("" + type).equals("*")) { return 0; } @@ -1487,7 +1487,7 @@ public class AVM2SourceGenerator implements SourceGenerator { } } - int slotScope = subMethod? 0 : 1; + int slotScope = subMethod ? 0 : 1; for (AssignableAVM2Item an : subvariables) { if (an instanceof NameAVM2Item) { @@ -1777,7 +1777,7 @@ public class AVM2SourceGenerator implements SourceGenerator { isNs = true; } } - + if ((type instanceof TypeItem) && (((TypeItem) type).fullTypeName.equals("Namespace"))) { isNs = true; } @@ -1840,7 +1840,7 @@ public class AVM2SourceGenerator implements SourceGenerator { if (t instanceof TraitSlotConst) { if (((TraitSlotConst) t).isNamespace()) { Namespace ns = a.constants.getNamespace(((TraitSlotConst) t).value_index); - return abc.constants.getNamespaceId(new Namespace(ns.kind, abc.constants.getStringId(ns.getName(a.constants, true),true)), 0, true); + return abc.constants.getNamespaceId(new Namespace(ns.kind, abc.constants.getStringId(ns.getName(a.constants, true), true)), 0, true); } } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/ActionScriptLexer.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/ActionScriptLexer.java index d1a6a6449..b240cf7f4 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/ActionScriptLexer.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/ActionScriptLexer.java @@ -1357,7 +1357,7 @@ public final class ActionScriptLexer { zzCurrentPosL += Character.charCount(zzInput); } } - int zzNext = zzTransL[ zzRowMapL[zzState] + zzCMapL[zzInput]]; + int zzNext = zzTransL[zzRowMapL[zzState] + zzCMapL[zzInput]]; if (zzNext == -1) { break zzForAction; } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/ActionScriptParser.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/ActionScriptParser.java index 8c91d2ce8..cb127b96e 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/ActionScriptParser.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/ActionScriptParser.java @@ -587,9 +587,9 @@ public class ActionScriptParser { throw new AVM2ParseException("Only one static keyword allowed", lexer.yyline()); } isStatic = true; - } else if(s.type == SymbolType.NAMESPACE) { + } else if (s.type == SymbolType.NAMESPACE) { break; - } else if(s.type == SymbolType.NATIVE) { + } else if (s.type == SymbolType.NATIVE) { throw new AVM2ParseException("Cannot compile native code", lexer.yyline()); } else if (s.group == SymbolGroup.IDENTIFIER) { customAccess = s.value.toString(); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/NameAVM2Item.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/NameAVM2Item.java index 67ae9ed35..e2571c1df 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/NameAVM2Item.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/NameAVM2Item.java @@ -12,7 +12,8 @@ * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with this library. */ + * License along with this library. + */ package com.jpexs.decompiler.flash.abc.avm2.parser.script; import com.jpexs.decompiler.flash.SourceGeneratorLocalData; @@ -237,9 +238,9 @@ public class NameAVM2Item extends AssignableAVM2Item { return toSourceMerge(localData, generator, ins(new GetScopeObjectIns(), slotScope), assignedValue, !(("" + assignedValue.returnType()).equals("" + type) && (basicTypes.contains("" + type))) ? generateCoerce(localData, generator, type) : null, needsReturn - ? dupSetTemp(localData, generator, ret_temp) : null, generateSetLoc(regNumber), slotNumber > -1 - ? ins(new SetSlotIns(), slotNumber) - : null, + ? dupSetTemp(localData, generator, ret_temp) : null, generateSetLoc(regNumber), slotNumber > -1 + ? ins(new SetSlotIns(), slotNumber) + : null, needsReturn ? getTemp(localData, generator, ret_temp) : null, killTemp(localData, generator, Arrays.asList(ret_temp))); } else { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/PropertyAVM2Item.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/PropertyAVM2Item.java index 57fdae658..2f99d8c3e 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/PropertyAVM2Item.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/PropertyAVM2Item.java @@ -258,7 +258,7 @@ public class PropertyAVM2Item extends AssignableAVM2Item { for (int i = 0; i < openedNamespaces.size(); i++) { int nsindex = openedNamespaces.get(i); int nsKind = abc.constants.constant_namespace.get(openedNamespaces.get(i)).kind; - String nsname = abc.constants.constant_namespace.get(openedNamespaces.get(i)).getName(abc.constants, true); + String nsname = abc.constants.constant_namespace.get(openedNamespaces.get(i)).getName(abc.constants, true); int name_index = 0; for (int m = 1; m < abc.constants.constant_multiname.size(); m++) { Multiname mname = abc.constants.constant_multiname.get(m); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/UnresolvedAVM2Item.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/UnresolvedAVM2Item.java index 3e1f4ca6a..01bf00bb0 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/UnresolvedAVM2Item.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/UnresolvedAVM2Item.java @@ -326,7 +326,7 @@ public class UnresolvedAVM2Item extends AssignableAVM2Item { impName = impName.substring(impName.lastIndexOf('.') + 1); } if (impName.equals(parts.get(0))) { - TypeItem ret = new TypeItem(imp); + TypeItem ret = new TypeItem(imp); resolved = ret; for (int i = 1; i < parts.size(); i++) { resolved = new PropertyAVM2Item(resolved, parts.get(i), abc, otherAbcs, openedNamespaces, new ArrayList()); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/methodinfo_parser/MethodInfoLexer.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/methodinfo_parser/MethodInfoLexer.java index 3b957c44c..386ac3147 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/methodinfo_parser/MethodInfoLexer.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/methodinfo_parser/MethodInfoLexer.java @@ -866,7 +866,7 @@ public final class MethodInfoLexer { zzInput = zzBufferL[zzCurrentPosL++]; } } - int zzNext = zzTransL[ zzRowMapL[zzState] + zzCMapL[zzInput]]; + int zzNext = zzTransL[zzRowMapL[zzState] + zzCMapL[zzInput]]; if (zzNext == -1) { break zzForAction; } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/MethodInfo.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/MethodInfo.java index fd0a47147..24cf1593e 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/MethodInfo.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/MethodInfo.java @@ -323,7 +323,7 @@ public class MethodInfo { } else { restName = "rest"; } - + HighlightData pdata = new HighlightData(); pdata.declaration = true; pdata.declaredType = "*"; diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/parser/pcode/FlasmLexer.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/parser/pcode/FlasmLexer.java index 26a5dfd17..ae6c1e9ac 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/parser/pcode/FlasmLexer.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/parser/pcode/FlasmLexer.java @@ -867,7 +867,7 @@ public final class FlasmLexer { zzInput = zzBufferL[zzCurrentPosL++]; } } - int zzNext = zzTransL[ zzRowMapL[zzState] + zzCMapL[zzInput]]; + int zzNext = zzTransL[zzRowMapL[zzState] + zzCMapL[zzInput]]; if (zzNext == -1) { break zzForAction; } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/parser/script/ActionScriptLexer.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/parser/script/ActionScriptLexer.java index ac343edc7..0e5c5d8d3 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/parser/script/ActionScriptLexer.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/parser/script/ActionScriptLexer.java @@ -1546,7 +1546,7 @@ public final class ActionScriptLexer { zzInput = zzBufferL[zzCurrentPosL++]; } } - int zzNext = zzTransL[ zzRowMapL[zzState] + zzCMapL[zzInput]]; + int zzNext = zzTransL[zzRowMapL[zzState] + zzCMapL[zzInput]]; if (zzNext == -1) { break zzForAction; } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/ImageExporter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/ImageExporter.java index ade0b93d9..84a0059c5 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/ImageExporter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/ImageExporter.java @@ -61,31 +61,29 @@ public class ImageExporter { if (settings.mode == ImageExportMode.JPEG) { fileFormat = "jpg"; } - + if (settings.mode == ImageExportMode.BMP) { fileFormat = "bmp"; } { - final ImageTag imageTag = (ImageTag) t; - final File file = new File(outdir + File.separator + Helper.makeFileName(imageTag.getCharacterExportFileName() + "." + fileFormat)); - final List ttags = tags; - final String ffileFormat = fileFormat; - - - new RetryTask(new RunnableIOEx() { - @Override - public void run() throws IOException { - if(ffileFormat.equals("bmp")){ - BMPFile.saveBitmap(imageTag.getImage().getBufferedImage(), file); - }else{ - ImageIO.write(imageTag.getImage().getBufferedImage(), ffileFormat.toUpperCase(Locale.ENGLISH), file); + final ImageTag imageTag = (ImageTag) t; + final File file = new File(outdir + File.separator + Helper.makeFileName(imageTag.getCharacterExportFileName() + "." + fileFormat)); + final String ffileFormat = fileFormat; + + new RetryTask(new RunnableIOEx() { + @Override + public void run() throws IOException { + if (ffileFormat.equals("bmp")) { + BMPFile.saveBitmap(imageTag.getImage().getBufferedImage(), file); + } else { + ImageIO.write(imageTag.getImage().getBufferedImage(), ffileFormat.toUpperCase(Locale.ENGLISH), file); + } } - } - }, handler).run(); - ret.add(file); + }, handler).run(); + ret.add(file); } - + } } return ret; diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/ShapeExporter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/ShapeExporter.java index fc1962a10..83456edf4 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/ShapeExporter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/ShapeExporter.java @@ -113,9 +113,9 @@ public class ShapeExporter { m.translate(-rect.Xmin, -rect.Ymin); m.scale(settings.zoom); st.toImage(0, 0, 0, null, 0, img, m, new CXFORMWITHALPHA()); - if(settings.mode==ShapeExportMode.PNG){ + if (settings.mode == ShapeExportMode.PNG) { ImageIO.write(img.getBufferedImage(), "PNG", new FileOutputStream(file)); - }else{ + } else { BMPFile.saveBitmap(img.getBufferedImage(), file); } break; diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/commonshape/Matrix.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/commonshape/Matrix.java index d8742b45a..0750e02ab 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/commonshape/Matrix.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/commonshape/Matrix.java @@ -288,16 +288,16 @@ public final class Matrix implements Cloneable { public double getTotalScaleY() { return Math.sqrt(rotateSkew1 * rotateSkew1 + scaleY * scaleY); } - - private int fromFloat(double f){ - return (int)(f * (1 << 16)); + + private int fromFloat(double f) { + return (int) (f * (1 << 16)); } - - public MATRIX toMATRIX(){ + + public MATRIX toMATRIX() { MATRIX result = new MATRIX(); - - result.translateX = (int)translateX; - result.translateY = (int)translateY; + + result.translateX = (int) translateX; + result.translateY = (int) translateY; result.hasRotate = true; result.hasScale = true; result.scaleX = fromFloat(scaleX); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/morphshape/MorphShapeExporterBase.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/morphshape/MorphShapeExporterBase.java index 782a8f3dc..a95a2b6a6 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/morphshape/MorphShapeExporterBase.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/morphshape/MorphShapeExporterBase.java @@ -297,7 +297,7 @@ public abstract class MorphShapeExporterBase implements IMorphShapeExporter { } fillStyleIdx = e.getFillStyleIdx(); pos = PointInt.MAX; - try { + if (fillStyleIdx - 1 < _fillStyles.size()) { Matrix matrix; Matrix matrixEnd; FILLSTYLE fillStyle = _fillStyles.get(fillStyleIdx - 1); @@ -342,7 +342,7 @@ public abstract class MorphShapeExporterBase implements IMorphShapeExporter { ); break; } - } catch (Exception ex) { + } else { // Font shapes define no fillstyles per se, but do reference fillstyle index 1, // which represents the font color. We just report null in this case. beginFill(null, null); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/shape/ShapeExporterBase.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/shape/ShapeExporterBase.java index 501d290e7..e32ef2bbf 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/shape/ShapeExporterBase.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/shape/ShapeExporterBase.java @@ -236,7 +236,7 @@ public abstract class ShapeExporterBase implements IShapeExporter { } fillStyleIdx = e.getFillStyleIdx(); pos = PointInt.MAX; - try { + if (fillStyleIdx - 1 < _fillStyles.size()) { Matrix matrix; FILLSTYLE fillStyle = _fillStyles.get(fillStyleIdx - 1); switch (fillStyle.fillStyleType) { @@ -273,7 +273,7 @@ public abstract class ShapeExporterBase implements IShapeExporter { ); break; } - } catch (Exception ex) { + } else { // Font shapes define no fillstyles per se, but do reference fillstyle index 1, // which represents the font color. We just report null in this case. beginFill(null); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/helpers/BMPFile.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/helpers/BMPFile.java index bc7bf87c9..8095e5060 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/helpers/BMPFile.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/helpers/BMPFile.java @@ -65,12 +65,12 @@ public class BMPFile extends Component { public static void saveBitmap(Image image, File file) throws IOException { BMPFile b = new BMPFile(); b.fo = new FileOutputStream(file); - try{ + try { b.save(image, image.getWidth(null), image.getHeight(null)); - }finally{ - try{ + } finally { + try { b.fo.close(); - }catch(Exception ex){ + } catch (Exception ex) { //ignore } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/helpers/hilight/HighlightData.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/helpers/hilight/HighlightData.java index 77b72a000..92ba8cca8 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/helpers/hilight/HighlightData.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/helpers/hilight/HighlightData.java @@ -23,7 +23,7 @@ import java.io.Serializable; * @author JPEXS */ public class HighlightData implements Cloneable, Serializable { - + public boolean declaration; public String declaredType; @@ -37,13 +37,13 @@ public class HighlightData implements Cloneable, Serializable { public long index; public long offset; - + public boolean isEmpty() { - return !declaration && declaredType == null && localName == null && - subtype == null && specialValue == null && - index == 0 && offset == 0; + return !declaration && declaredType == null && localName == null + && subtype == null && specialValue == null + && index == 0 && offset == 0; } - + public void merge(HighlightData data) { if (data.declaration) { declaration = data.declaration; diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/helpers/hilight/HighlightSpecialType.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/helpers/hilight/HighlightSpecialType.java index 4193b67f6..28fb4f53c 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/helpers/hilight/HighlightSpecialType.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/helpers/hilight/HighlightSpecialType.java @@ -21,8 +21,8 @@ package com.jpexs.decompiler.flash.helpers.hilight; * @author JPEXS */ public enum HighlightSpecialType { - - PARAM_NAME, PARAM, OPTIONAL, RETURNS, + + PARAM_NAME, PARAM, OPTIONAL, RETURNS, TYPE_NAME, CLASS_NAME, METHOD_NAME, TRAIT_TYPE, TRAIT_NAME, TRAIT_TYPE_NAME, TRAIT_VALUE, SLOT_ID, DISP_ID, diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/helpers/hilight/Highlighting.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/helpers/hilight/Highlighting.java index 69e7ee86f..6cf490fef 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/helpers/hilight/Highlighting.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/helpers/hilight/Highlighting.java @@ -112,7 +112,7 @@ public class Highlighting implements Serializable { public static Highlighting searchOffset(List list, long offset) { return searchOffset(list, offset, -1, -1); } - + public static Highlighting searchOffset(List list, long offset, long from, long to) { looph: for (Highlighting h : list) { @@ -139,7 +139,7 @@ public class Highlighting implements Serializable { public static Highlighting searchIndex(List list, long index) { return searchIndex(list, index, -1, -1); } - + public static Highlighting searchIndex(List list, long index, long from, long to) { looph: for (Highlighting h : list) { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/ShapeImporter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/ShapeImporter.java index 1f6805a65..8f8f84a0b 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/ShapeImporter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/ShapeImporter.java @@ -38,27 +38,27 @@ import javax.imageio.ImageIO; * @author JPEXS */ public class ShapeImporter { - + public Tag importImage(ShapeTag st, byte[] newData) throws IOException { SWF swf = st.getSwf(); - - if(newData[0] == 'B' && newData[1] == 'M'){ + + if (newData[0] == 'B' && newData[1] == 'M') { BufferedImage b = ImageIO.read(new ByteArrayInputStream(newData)); - ByteArrayOutputStream baos=new ByteArrayOutputStream(); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); ImageIO.write(b, "PNG", baos); newData = baos.toByteArray(); } - + DefineBitsJPEG2Tag jpeg2Tag = new DefineBitsJPEG2Tag(swf, null, swf.getNextCharacterId(), newData); jpeg2Tag.setModified(true); swf.tags.add(jpeg2Tag); swf.updateCharacters(); st.setModified(true); SHAPEWITHSTYLE shapes = jpeg2Tag.getShape(st.getRect(new HashSet()), true); - + if (st instanceof DefineShapeTag) { DefineShapeTag dst = (DefineShapeTag) st; - dst.shapes = shapes; + dst.shapes = shapes; } else if (st instanceof DefineShape2Tag) { DefineShape2Tag dst = (DefineShape2Tag) st; dst.shapes = shapes; @@ -69,7 +69,7 @@ public class ShapeImporter { DefineShape4Tag dst = (DefineShape4Tag) st; dst.shapes = shapes; } - + return (Tag) st; } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/TextImporter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/TextImporter.java new file mode 100644 index 000000000..d3a8498db --- /dev/null +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/TextImporter.java @@ -0,0 +1,183 @@ +/* + * Copyright (C) 2014 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.importers; + +import com.jpexs.decompiler.flash.SWF; +import com.jpexs.decompiler.flash.configuration.Configuration; +import com.jpexs.decompiler.flash.exporters.TextExporter; +import com.jpexs.decompiler.flash.tags.Tag; +import com.jpexs.decompiler.flash.tags.base.MissingCharacterHandler; +import com.jpexs.decompiler.flash.tags.base.TextImportErrorHandler; +import com.jpexs.decompiler.flash.tags.base.TextTag; +import com.jpexs.decompiler.flash.tags.text.TextParseException; +import com.jpexs.helpers.Helper; +import com.jpexs.helpers.Path; +import java.io.File; +import java.io.FilenameFilter; +import java.util.HashMap; +import java.util.Map; +import java.util.regex.Pattern; + +/** + * + * @author JPEXS + */ +public class TextImporter { + + private final MissingCharacterHandler missingCharacterHandler; + private final TextImportErrorHandler errorHandler; + + public TextImporter(MissingCharacterHandler missingCharacterHandler, TextImportErrorHandler errorHandler) { + this.missingCharacterHandler = missingCharacterHandler; + this.errorHandler = errorHandler; + } + + private Map splitTextRecords(String texts) { + String[] textsArr = texts.split(Helper.newLine + Configuration.textExportSingleFileSeparator.get() + Helper.newLine); + String recordSeparator = Helper.newLine + Configuration.textExportSingleFileRecordSeparator.get() + Helper.newLine; + Map result = new HashMap<>(); + for (String text : textsArr) { + String[] textArr = text.split(Helper.newLine, 2); + String idLine = textArr[0]; + if (idLine.startsWith("ID:")) { + int id = Integer.parseInt(idLine.substring(3).trim()); + String[] records = textArr[1].split(recordSeparator); + result.put(id, records); + } else { + if (errorHandler.handle()) { + return null; + } + } + } + return result; + } + + public void importTextsSingleFile(File textsFile, SWF swf) { + String texts = Helper.readTextFile(textsFile.getPath()); + Map records = splitTextRecords(texts); + if (records != null) { + for (int characterId : records.keySet()) { + for (Tag tag : swf.tags) { + if (tag instanceof TextTag) { + TextTag textTag = (TextTag) tag; + if (textTag.getCharacterId() == characterId) { + String[] currentRecords = records.get(characterId); + String text = textTag.getFormattedText(); + if (!saveText(textTag, text, currentRecords)) { + return; + } + break; + } + } + } + } + } + } + + public void importTextsSingleFileFormatted(File textsFile, SWF swf) { + String texts = Helper.readTextFile(textsFile.getPath()); + Map records = splitTextRecords(texts); + if (records != null) { + for (int characterId : records.keySet()) { + for (Tag tag : swf.tags) { + if (tag instanceof TextTag) { + TextTag textTag = (TextTag) tag; + if (textTag.getCharacterId() == characterId) { + String[] currentRecords = records.get(characterId); + if (!saveText(textTag, currentRecords[0], null)) { + return; + } + break; + } + } + } + } + } + } + + public void importTextsMultipleFiles(String folder, SWF swf) { + File textsFolder = new File(Path.combine(folder, TextExporter.TEXT_EXPORT_FOLDER)); + String[] files = textsFolder.list(new FilenameFilter() { + + private final Pattern pat = Pattern.compile("\\d+\\.txt", Pattern.CASE_INSENSITIVE); + + @Override + public boolean accept(File dir, String name) { + + return pat.matcher(name).matches(); + } + }); + + if (files == null) { + return; + } + + for (String fileName : files) { + String texts = Helper.readTextFile(Path.combine(textsFolder.getPath(), fileName)); + int characterId = Integer.parseInt(fileName.split("\\.")[0]); + String recordSeparator = Helper.newLine + Configuration.textExportSingleFileRecordSeparator.get() + Helper.newLine; + boolean formatted = !texts.contains(recordSeparator) && texts.startsWith("[" + Helper.newLine); + if (!formatted) { + String[] records = texts.split(recordSeparator); + for (Tag tag : swf.tags) { + if (tag instanceof TextTag) { + TextTag textTag = (TextTag) tag; + if (textTag.getCharacterId() == characterId) { + String text = textTag.getFormattedText(); + if (!saveText(textTag, text, records)) { + return; + } + break; + } + } + } + } else { + for (Tag tag : swf.tags) { + if (tag instanceof TextTag) { + TextTag textTag = (TextTag) tag; + if (textTag.getCharacterId() == characterId) { + if (!saveText(textTag, texts, null)) { + return; + } + break; + } + } + } + } + } + } + + /** + * Stores the new text to the text tag + * + * @param textTag + * @param formattedText + * @param texts + * @return If false the processing should be interrupted + */ + public boolean saveText(TextTag textTag, String formattedText, String[] texts) { + try { + if (textTag.setFormattedText(missingCharacterHandler, formattedText, texts)) { + return true; + } + + return !errorHandler.handle(); + } catch (TextParseException ex) { + return !errorHandler.handle(ex.text, ex.line); + } + } +} diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineBitsJPEG3Tag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineBitsJPEG3Tag.java index e65feee8c..cb5f3c55f 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineBitsJPEG3Tag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineBitsJPEG3Tag.java @@ -45,7 +45,7 @@ public class DefineBitsJPEG3Tag extends ImageTag implements AloneTag { public byte[] bitmapAlphaData; public static final int ID = 35; - + @Override public int getCharacterId() { return characterID; diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineButton2Tag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineButton2Tag.java index 9a7f523e0..a74da76cf 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineButton2Tag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineButton2Tag.java @@ -207,7 +207,7 @@ public class DefineButton2Tag extends ButtonTag implements Container { return modified; } - private static final Cache rectCache = Cache.getInstance(true,"rect_button2"); + private static final Cache rectCache = Cache.getInstance(true, "rect_button2"); @Override public RECT getRect(Set added) { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineButtonTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineButtonTag.java index 75e6a12a5..8faf7f522 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineButtonTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineButtonTag.java @@ -245,7 +245,7 @@ public class DefineButtonTag extends ButtonTag implements ASMSource { return modified; } - private static final Cache rectCache = Cache.getInstance(true,"rect_button"); + private static final Cache rectCache = Cache.getInstance(true, "rect_button"); @Override public RECT getRect(Set added) { 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 cb6e94319..5c8882dbc 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 @@ -406,28 +406,28 @@ public class DefineEditTextTag extends TextTag { try { bounds.Xmin = Integer.parseInt(paramValue); } catch (NumberFormatException nfe) { - throw new TextParseException("Invalid xmin value. Number expected.", lexer.yyline()); + throw new TextParseException("Invalid xmin value. Number expected. Found: " + paramValue, lexer.yyline()); } break; case "ymin": try { bounds.Ymin = Integer.parseInt(paramValue); } catch (NumberFormatException nfe) { - throw new TextParseException("Invalid ymin value. Number expected.", lexer.yyline()); + throw new TextParseException("Invalid ymin value. Number expected. Found: " + paramValue, lexer.yyline()); } break; case "xmax": try { bounds.Xmax = Integer.parseInt(paramValue); } catch (NumberFormatException nfe) { - throw new TextParseException("Invalid xmax value. Number expected.", lexer.yyline()); + throw new TextParseException("Invalid xmax value. Number expected. Found: " + paramValue, lexer.yyline()); } break; case "ymax": try { bounds.Ymax = Integer.parseInt(paramValue); } catch (NumberFormatException nfe) { - throw new TextParseException("Invalid ymax value. Number expected.", lexer.yyline()); + throw new TextParseException("Invalid ymax value. Number expected. Found: " + paramValue, lexer.yyline()); } break; case "wordwrap": @@ -484,7 +484,7 @@ public class DefineEditTextTag extends TextTag { try { fontId = Integer.parseInt(paramValue); } catch (NumberFormatException ne) { - throw new TextParseException("Invalid font value. Number expected.", lexer.yyline()); + throw new TextParseException("Invalid font value. Number expected. Found: " + paramValue, lexer.yyline()); } break; case "fontclass": @@ -494,7 +494,7 @@ public class DefineEditTextTag extends TextTag { try { fontHeight = Integer.parseInt(paramValue); } catch (NumberFormatException ne) { - throw new TextParseException("Invalid height value. Number expected.", lexer.yyline()); + throw new TextParseException("Invalid height value. Number expected. Found: " + paramValue, lexer.yyline()); } break; case "color": @@ -502,14 +502,14 @@ public class DefineEditTextTag extends TextTag { if (m.matches()) { textColor = new RGBA(Integer.parseInt(m.group(2), 16), Integer.parseInt(m.group(3), 16), Integer.parseInt(m.group(4), 16), Integer.parseInt(m.group(1), 16)); } else { - throw new TextParseException("Invalid color. Valid format is #aarrggbb.", lexer.yyline()); + throw new TextParseException("Invalid color. Valid format is #aarrggbb. Found: " + paramValue, lexer.yyline()); } break; case "maxlength": try { maxLength = Integer.parseInt(paramValue); } catch (NumberFormatException ne) { - throw new TextParseException("Invalid maxLength value. Number expected.", lexer.yyline()); + throw new TextParseException("Invalid maxLength value. Number expected. Found: " + paramValue, lexer.yyline()); } break; case "align": @@ -527,42 +527,42 @@ public class DefineEditTextTag extends TextTag { align = 3; break; default: - throw new TextParseException("Invalid align value. Expected one of: left,right,center or justify.", lexer.yyline()); + throw new TextParseException("Invalid align value. Expected one of: left,right,center or justify. Found: " + paramValue, lexer.yyline()); } break; case "leftmargin": try { leftMargin = Integer.parseInt(paramValue); } catch (NumberFormatException ne) { - throw new TextParseException("Invalid leftmargin value. Number expected.", lexer.yyline()); + throw new TextParseException("Invalid leftmargin value. Number expected. Found: " + paramValue, lexer.yyline()); } break; case "rightmargin": try { rightMargin = Integer.parseInt(paramValue); } catch (NumberFormatException ne) { - throw new TextParseException("Invalid rightmargin value. Number expected.", lexer.yyline()); + throw new TextParseException("Invalid rightmargin value. Number expected. Found: " + paramValue, lexer.yyline()); } break; case "indent": try { indent = Integer.parseInt(paramValue); } catch (NumberFormatException ne) { - throw new TextParseException("Invalid indent value. Number expected.", lexer.yyline()); + throw new TextParseException("Invalid indent value. Number expected. Found: " + paramValue, lexer.yyline()); } break; case "leading": try { leading = Integer.parseInt(paramValue); } catch (NumberFormatException ne) { - throw new TextParseException("Invalid leading value. Number expected.", lexer.yyline()); + throw new TextParseException("Invalid leading value. Number expected. Found: " + paramValue, lexer.yyline()); } break; case "variablename": variableName = paramValue; break; default: - throw new TextParseException("Unrecognized parameter name", lexer.yyline()); + throw new TextParseException("Unrecognized parameter name: " + paramName, lexer.yyline()); } break; case TEXT: @@ -571,6 +571,7 @@ public class DefineEditTextTag extends TextTag { } } + setModified(true); this.bounds = bounds; if (formattedText.length() > 0) { initialText = formattedText; @@ -625,8 +626,8 @@ public class DefineEditTextTag extends TextTag { Logger.getLogger(DefineEditTextTag.class.getName()).log(Level.SEVERE, null, ex); return false; } - return true; + return true; } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineSpriteTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineSpriteTag.java index 1facbf61d..55789e057 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineSpriteTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/DefineSpriteTag.java @@ -122,7 +122,7 @@ public class DefineSpriteTag extends CharacterTag implements Container, Drawable return ret; } - private static final Cache rectCache = Cache.getInstance(true,"rect_sprite"); + private static final Cache rectCache = Cache.getInstance(true, "rect_sprite"); @Override public RECT getRect(Set added) { 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 1856427d2..d032277f8 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 @@ -179,7 +179,6 @@ public class DefineText2Tag extends TextTag { @Override public boolean setFormattedText(MissingCharacterHandler missingCharHandler, String formattedText, String[] texts) throws TextParseException { - List oldTextRecords = textRecords; try { TextLexer lexer = new TextLexer(new StringReader(formattedText)); ParsedSymbol s = null; @@ -205,15 +204,15 @@ public class DefineText2Tag extends TextTag { case PARAMETER: String paramName = (String) s.values[0]; String paramValue = (String) s.values[1]; - if (paramName.equals("color")) { - Matcher m = Pattern.compile("#([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])").matcher(paramValue); - if (m.matches()) { - colorA = new RGBA(Integer.parseInt(m.group(2), 16), Integer.parseInt(m.group(3), 16), Integer.parseInt(m.group(4), 16), Integer.parseInt(m.group(1), 16)); - } else { - throw new TextParseException("Invalid color. Valid format is #aarrggbb.", lexer.yyline()); - } - } switch (paramName) { + case "color": + Matcher m = Pattern.compile("#([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])").matcher(paramValue); + if (m.matches()) { + colorA = new RGBA(Integer.parseInt(m.group(2), 16), Integer.parseInt(m.group(3), 16), Integer.parseInt(m.group(4), 16), Integer.parseInt(m.group(1), 16)); + } else { + throw new TextParseException("Invalid color. Valid format is #aarrggbb. Found: " + paramValue, lexer.yyline()); + } + break; case "font": try { fontId = Integer.parseInt(paramValue); @@ -231,14 +230,14 @@ public class DefineText2Tag extends TextTag { throw new TextParseException("Font not found", lexer.yyline()); } } catch (NumberFormatException nfe) { - throw new TextParseException("Invalid font id - number expected.", lexer.yyline()); + throw new TextParseException("Invalid font id - number expected. Found: " + paramValue, lexer.yyline()); } break; case "height": try { textHeight = Integer.parseInt(paramValue); } catch (NumberFormatException nfe) { - throw new TextParseException("Invalid font height - number expected.", lexer.yyline()); + throw new TextParseException("Invalid font height - number expected. Found: " + paramValue, lexer.yyline()); } break; case "x": @@ -246,7 +245,7 @@ public class DefineText2Tag extends TextTag { x = Integer.parseInt(paramValue); currentX = x; } catch (NumberFormatException nfe) { - throw new TextParseException("Invalid x position - number expected.", lexer.yyline()); + throw new TextParseException("Invalid x position - number expected. Found: " + paramValue, lexer.yyline()); } break; case "y": @@ -254,35 +253,35 @@ public class DefineText2Tag extends TextTag { y = Integer.parseInt(paramValue); currentY = y; } catch (NumberFormatException nfe) { - throw new TextParseException("Invalid y position - number expected.", lexer.yyline()); + throw new TextParseException("Invalid y position - number expected. Found: " + paramValue, lexer.yyline()); } break; case "xmin": try { textBounds.Xmin = Integer.parseInt(paramValue); } catch (NumberFormatException nfe) { - throw new TextParseException("Invalid xmin position - number expected.", lexer.yyline()); + throw new TextParseException("Invalid xmin position - number expected. Found: " + paramValue, lexer.yyline()); } break; case "xmax": try { textBounds.Xmax = Integer.parseInt(paramValue); } catch (NumberFormatException nfe) { - throw new TextParseException("Invalid xmax position - number expected.", lexer.yyline()); + throw new TextParseException("Invalid xmax position - number expected. Found: " + paramValue, lexer.yyline()); } break; case "ymin": try { textBounds.Ymin = Integer.parseInt(paramValue); } catch (NumberFormatException nfe) { - throw new TextParseException("Invalid ymin position - number expected.", lexer.yyline()); + throw new TextParseException("Invalid ymin position - number expected. Found: " + paramValue, lexer.yyline()); } break; case "ymax": try { textBounds.Ymax = Integer.parseInt(paramValue); } catch (NumberFormatException nfe) { - throw new TextParseException("Invalid ymax position - number expected.", lexer.yyline()); + throw new TextParseException("Invalid ymax position - number expected. Found: " + paramValue, lexer.yyline()); } break; case "scalex": @@ -290,7 +289,7 @@ public class DefineText2Tag extends TextTag { textMatrix.scaleX = Integer.parseInt(paramValue); textMatrix.hasScale = true; } catch (NumberFormatException nfe) { - throw new TextParseException("Invalid scalex value - number expected.", lexer.yyline()); + throw new TextParseException("Invalid scalex value - number expected. Found: " + paramValue, lexer.yyline()); } break; case "scaley": @@ -298,7 +297,7 @@ public class DefineText2Tag extends TextTag { textMatrix.scaleY = Integer.parseInt(paramValue); textMatrix.hasScale = true; } catch (NumberFormatException nfe) { - throw new TextParseException("Invalid scalex value - number expected.", lexer.yyline()); + throw new TextParseException("Invalid scalex value - number expected. Found: " + paramValue, lexer.yyline()); } break; case "rotateskew0": @@ -306,7 +305,7 @@ public class DefineText2Tag extends TextTag { textMatrix.rotateSkew0 = Integer.parseInt(paramValue); textMatrix.hasRotate = true; } catch (NumberFormatException nfe) { - throw new TextParseException("Invalid rotateskew0 value - number expected.", lexer.yyline()); + throw new TextParseException("Invalid rotateskew0 value - number expected. Found: " + paramValue, lexer.yyline()); } break; case "rotateskew1": @@ -314,23 +313,25 @@ public class DefineText2Tag extends TextTag { textMatrix.rotateSkew1 = Integer.parseInt(paramValue); textMatrix.hasRotate = true; } catch (NumberFormatException nfe) { - throw new TextParseException("Invalid rotateskew1 value - number expected.", lexer.yyline()); + throw new TextParseException("Invalid rotateskew1 value - number expected. Found: " + paramValue, lexer.yyline()); } break; case "translatex": try { textMatrix.translateX = Integer.parseInt(paramValue); } catch (NumberFormatException nfe) { - throw new TextParseException("Invalid translatex value - number expected.", lexer.yyline()); + throw new TextParseException("Invalid translatex value - number expected. Found: " + paramValue, lexer.yyline()); } break; case "translatey": try { textMatrix.translateY = Integer.parseInt(paramValue); } catch (NumberFormatException nfe) { - throw new TextParseException("Invalid translatey value - number expected.", lexer.yyline()); + throw new TextParseException("Invalid translatey value - number expected. Found: " + paramValue, lexer.yyline()); } break; + default: + throw new TextParseException("Unrecognized parameter name: " + paramName, lexer.yyline()); } break; case TEXT: @@ -411,17 +412,16 @@ public class DefineText2Tag extends TextTag { } } + + setModified(true); this.textRecords = textRecords; this.textBounds = textBounds; - //this.textBounds.Xmin = minX; - //this.textBounds.Xmax = maxX; } catch (IOException ex) { - textRecords = oldTextRecords; return false; } catch (TextParseException ex) { - textRecords = oldTextRecords; throw ex; } + 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 524c59b3c..fd4aa2b8a 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 @@ -185,11 +185,10 @@ public class DefineTextTag extends TextTag { @Override public boolean setFormattedText(MissingCharacterHandler missingCharHandler, String formattedText, String[] texts) throws TextParseException { - List oldTextRecords = textRecords; try { TextLexer lexer = new TextLexer(new StringReader(formattedText)); ParsedSymbol s = null; - textRecords = new ArrayList<>(); + List textRecords = new ArrayList<>(); RGB color = null; int fontId = -1; int textHeight = -1; @@ -217,7 +216,7 @@ public class DefineTextTag extends TextTag { if (m.matches()) { color = new RGB(Integer.parseInt(m.group(1), 16), Integer.parseInt(m.group(2), 16), Integer.parseInt(m.group(3), 16)); } else { - throw new TextParseException("Invalid color. Valid format is #rrggbb.", lexer.yyline()); + throw new TextParseException("Invalid color. Valid format is #rrggbb. Found: " + paramValue, lexer.yyline()); } break; case "font": @@ -237,14 +236,14 @@ public class DefineTextTag extends TextTag { throw new TextParseException("Font not found", lexer.yyline()); } } catch (NumberFormatException nfe) { - throw new TextParseException("Invalid font id - number expected.", lexer.yyline()); + throw new TextParseException("Invalid font id - number expected. Found: " + paramValue, lexer.yyline()); } break; case "height": try { textHeight = Integer.parseInt(paramValue); } catch (NumberFormatException nfe) { - throw new TextParseException("Invalid font height - number expected.", lexer.yyline()); + throw new TextParseException("Invalid font height - number expected. Found: " + paramValue, lexer.yyline()); } break; case "x": @@ -252,7 +251,7 @@ public class DefineTextTag extends TextTag { x = Integer.parseInt(paramValue); currentX = x; } catch (NumberFormatException nfe) { - throw new TextParseException("Invalid x position - number expected.", lexer.yyline()); + throw new TextParseException("Invalid x position - number expected. Found: " + paramValue, lexer.yyline()); } break; case "y": @@ -260,35 +259,35 @@ public class DefineTextTag extends TextTag { y = Integer.parseInt(paramValue); currentY = y; } catch (NumberFormatException nfe) { - throw new TextParseException("Invalid y position - number expected.", lexer.yyline()); + throw new TextParseException("Invalid y position - number expected. Found: " + paramValue, lexer.yyline()); } break; case "xmin": try { textBounds.Xmin = Integer.parseInt(paramValue); } catch (NumberFormatException nfe) { - throw new TextParseException("Invalid xmin position - number expected.", lexer.yyline()); + throw new TextParseException("Invalid xmin position - number expected. Found: " + paramValue, lexer.yyline()); } break; case "xmax": try { textBounds.Xmax = Integer.parseInt(paramValue); } catch (NumberFormatException nfe) { - throw new TextParseException("Invalid xmax position - number expected.", lexer.yyline()); + throw new TextParseException("Invalid xmax position - number expected. Found: " + paramValue, lexer.yyline()); } break; case "ymin": try { textBounds.Ymin = Integer.parseInt(paramValue); } catch (NumberFormatException nfe) { - throw new TextParseException("Invalid ymin position - number expected.", lexer.yyline()); + throw new TextParseException("Invalid ymin position - number expected. Found: " + paramValue, lexer.yyline()); } break; case "ymax": try { textBounds.Ymax = Integer.parseInt(paramValue); } catch (NumberFormatException nfe) { - throw new TextParseException("Invalid ymax position - number expected.", lexer.yyline()); + throw new TextParseException("Invalid ymax position - number expected. Found: " + paramValue, lexer.yyline()); } break; case "scalex": @@ -296,7 +295,7 @@ public class DefineTextTag extends TextTag { textMatrix.scaleX = Integer.parseInt(paramValue); textMatrix.hasScale = true; } catch (NumberFormatException nfe) { - throw new TextParseException("Invalid scalex value - number expected.", lexer.yyline()); + throw new TextParseException("Invalid scalex value - number expected. Found: " + paramValue, lexer.yyline()); } break; case "scaley": @@ -304,7 +303,7 @@ public class DefineTextTag extends TextTag { textMatrix.scaleY = Integer.parseInt(paramValue); textMatrix.hasScale = true; } catch (NumberFormatException nfe) { - throw new TextParseException("Invalid scalex value - number expected.", lexer.yyline()); + throw new TextParseException("Invalid scalex value - number expected. Found: " + paramValue, lexer.yyline()); } break; case "rotateskew0": @@ -312,7 +311,7 @@ public class DefineTextTag extends TextTag { textMatrix.rotateSkew0 = Integer.parseInt(paramValue); textMatrix.hasRotate = true; } catch (NumberFormatException nfe) { - throw new TextParseException("Invalid rotateskew0 value - number expected.", lexer.yyline()); + throw new TextParseException("Invalid rotateskew0 value - number expected. Found: " + paramValue, lexer.yyline()); } break; case "rotateskew1": @@ -320,23 +319,25 @@ public class DefineTextTag extends TextTag { textMatrix.rotateSkew1 = Integer.parseInt(paramValue); textMatrix.hasRotate = true; } catch (NumberFormatException nfe) { - throw new TextParseException("Invalid rotateskew1 value - number expected.", lexer.yyline()); + throw new TextParseException("Invalid rotateskew1 value - number expected. Found: " + paramValue, lexer.yyline()); } break; case "translatex": try { textMatrix.translateX = Integer.parseInt(paramValue); } catch (NumberFormatException nfe) { - throw new TextParseException("Invalid translatex value - number expected.", lexer.yyline()); + throw new TextParseException("Invalid translatex value - number expected. Found: " + paramValue, lexer.yyline()); } break; case "translatey": try { textMatrix.translateY = Integer.parseInt(paramValue); } catch (NumberFormatException nfe) { - throw new TextParseException("Invalid translatey value - number expected.", lexer.yyline()); + throw new TextParseException("Invalid translatey value - number expected. Found: " + paramValue, lexer.yyline()); } break; + default: + throw new TextParseException("Unrecognized parameter name: " + paramName, lexer.yyline()); } break; case TEXT: @@ -418,17 +419,17 @@ public class DefineTextTag extends TextTag { } } + + setModified(true); + this.textRecords = textRecords; this.textMatrix = textMatrix; this.textBounds = textBounds; - //this.textBounds.Xmin = minX; - //this.textBounds.Xmax = maxX; } catch (IOException ex) { - textRecords = oldTextRecords; return false; } catch (TextParseException ex) { - textRecords = oldTextRecords; throw ex; } + return true; } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/PlaceObject2Tag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/PlaceObject2Tag.java index b36988b2d..58f6af895 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/PlaceObject2Tag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/PlaceObject2Tag.java @@ -409,12 +409,12 @@ public class PlaceObject2Tag extends CharacterIdTag implements Container, PlaceO return null; } } - + @Override public void writeTagWithMatrix(SWFOutputStream sos, MATRIX m) throws IOException { - MATRIX old=matrix; + MATRIX old = matrix; matrix = m; - boolean mod=isModified(); + boolean mod = isModified(); setModified(true); super.writeTag(sos); setModified(mod); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/PlaceObject3Tag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/PlaceObject3Tag.java index 9613d5abc..0efeb52f8 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/PlaceObject3Tag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/PlaceObject3Tag.java @@ -538,12 +538,12 @@ public class PlaceObject3Tag extends CharacterIdTag implements Container, PlaceO return null; } } - + @Override public void writeTagWithMatrix(SWFOutputStream sos, MATRIX m) throws IOException { - MATRIX old=matrix; + MATRIX old = matrix; matrix = m; - boolean mod=isModified(); + boolean mod = isModified(); setModified(true); super.writeTag(sos); setModified(mod); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/PlaceObject4Tag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/PlaceObject4Tag.java index 14bbb5895..752cdbc85 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/PlaceObject4Tag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/PlaceObject4Tag.java @@ -541,12 +541,12 @@ public class PlaceObject4Tag extends CharacterIdTag implements Container, PlaceO return null; } } - + @Override public void writeTagWithMatrix(SWFOutputStream sos, MATRIX m) throws IOException { - MATRIX old=matrix; + MATRIX old = matrix; matrix = m; - boolean mod=isModified(); + boolean mod = isModified(); setModified(true); super.writeTag(sos); setModified(mod); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/PlaceObjectTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/PlaceObjectTag.java index ccb4b9b24..5010d9f62 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/PlaceObjectTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/PlaceObjectTag.java @@ -221,14 +221,13 @@ public class PlaceObjectTag extends CharacterIdTag implements PlaceObjectTypeTag @Override public void writeTagWithMatrix(SWFOutputStream sos, MATRIX m) throws IOException { - MATRIX old=matrix; + MATRIX old = matrix; matrix = m; - boolean mod=isModified(); + boolean mod = isModified(); setModified(true); super.writeTag(sos); setModified(mod); matrix = old; } - - + } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/TagChangedListener.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/TagChangedListener.java index ab49a33ab..93b05270d 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/TagChangedListener.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/TagChangedListener.java @@ -21,6 +21,6 @@ package com.jpexs.decompiler.flash.tags; * @author JPEXS */ public interface TagChangedListener { - + public void handleEvent(Tag tag); } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/base/ImageTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/base/ImageTag.java index ad396fa96..796360e9c 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/base/ImageTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/base/ImageTag.java @@ -114,7 +114,7 @@ public abstract class ImageTag extends CharacterTag implements DrawableTag { RECT rect = getRect(new HashSet()); return getShape(rect, false); } - + public SHAPEWITHSTYLE getShape(RECT rect, boolean fill) { boolean translated = rect.Xmin != 0 || rect.Ymin != 0; SHAPEWITHSTYLE shape = new SHAPEWITHSTYLE(); @@ -125,7 +125,7 @@ public abstract class ImageTag extends CharacterTag implements DrawableTag { fillStyle.bitmapId = getCharacterId(); MATRIX matrix = new MATRIX(); matrix.hasScale = true; - if (fill) { + if (fill) { RECT imageRect = getRect(new HashSet()); matrix.scaleX = (int) ((((long) SWF.unitDivisor) << 16) * rect.getWidth() / imageRect.getWidth()); matrix.scaleY = (int) ((((long) SWF.unitDivisor) << 16) * rect.getHeight() / imageRect.getHeight()); @@ -212,7 +212,7 @@ public abstract class ImageTag extends CharacterTag implements DrawableTag { public Shape getOutline(int frame, int time, int ratio, DepthState stateUnderCursor, int mouseButton, Matrix transformation) { return transformation.toTransform().createTransformedShape(getShape().getOutline()); } - + public void clearCache() { cachedImage = null; } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/base/PlaceObjectTypeTag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/base/PlaceObjectTypeTag.java index f3081e9b4..86e039c06 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/base/PlaceObjectTypeTag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/base/PlaceObjectTypeTag.java @@ -64,6 +64,6 @@ public interface PlaceObjectTypeTag { public int getRatio(); public CLIPACTIONS getClipActions(); - - public void writeTagWithMatrix(SWFOutputStream sos,MATRIX m) throws IOException; + + public void writeTagWithMatrix(SWFOutputStream sos, MATRIX m) throws IOException; } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/base/TextImportErrorHandler.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/base/TextImportErrorHandler.java new file mode 100644 index 000000000..d03ee2522 --- /dev/null +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/base/TextImportErrorHandler.java @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2014 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.tags.base; + +/** + * + * @author JPEXS + */ +public abstract class TextImportErrorHandler { + + public abstract boolean handle(); + + public abstract boolean handle(String message, long line); +} diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/text/TextLexer.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/text/TextLexer.java index 34e49a913..c56ca230d 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/text/TextLexer.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/text/TextLexer.java @@ -637,7 +637,7 @@ public final class TextLexer { zzInput = zzBufferL[zzCurrentPosL++]; } } - int zzNext = zzTransL[ zzRowMapL[zzState] + zzCMapL[zzInput]]; + int zzNext = zzTransL[zzRowMapL[zzState] + zzCMapL[zzInput]]; if (zzNext == -1) { break zzForAction; } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/ColorTransform.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/ColorTransform.java index 09cc6571f..fff9fde2a 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/ColorTransform.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/ColorTransform.java @@ -62,7 +62,7 @@ public class ColorTransform implements Cloneable { r2.inShape3 = r.inShape3; r2.ratio = r.ratio; r2.color = apply(r.color); - ret[i] = r2; + ret[i] = r2; } return ret; } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/MATRIX.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/MATRIX.java index c516a8d0b..756bf3cd9 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/MATRIX.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/MATRIX.java @@ -107,8 +107,6 @@ public class MATRIX implements Serializable { return "[MATRIX scale:" + getScaleXFloat() + "," + getScaleYFloat() + ", rotate:" + getRotateSkew0Float() + "," + getRotateSkew1Float() + ", translate:" + translateX + "," + translateY + "]"; } - - private float toFloat(int i) { return ((float) i) / (1 << 16); } @@ -162,7 +160,7 @@ public class MATRIX implements Serializable { public int getScaleY() { return (hasScale ? (scaleY) : (1 << 16)); } - + public boolean isEmpty() { return (translateX == 0) && (translateY == 0) && (!hasRotate) && (!hasScale); } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/annotations/parser/ConditionLexer.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/annotations/parser/ConditionLexer.java index c77592e7f..fba59899f 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/annotations/parser/ConditionLexer.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/annotations/parser/ConditionLexer.java @@ -656,7 +656,7 @@ public final class ConditionLexer { zzInput = zzBufferL[zzCurrentPosL++]; } } - int zzNext = zzTransL[ zzRowMapL[zzState] + zzCMapL[zzInput]]; + int zzNext = zzTransL[zzRowMapL[zzState] + zzCMapL[zzInput]]; if (zzNext == -1) { break zzForAction; } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/gfx/EdgeType.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/gfx/EdgeType.java index 541193b6a..cef01392c 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/gfx/EdgeType.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/gfx/EdgeType.java @@ -103,7 +103,7 @@ public class EdgeType implements Serializable { public SHAPERECORD toSHAPERECORD() { int multiplier = 1; StraightEdgeRecord ser; - CurvedEdgeRecord cer; + CurvedEdgeRecord cer; switch (data[0]) { case Edge_HLine: ser = new StraightEdgeRecord(); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/xfl/XFLConverter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/xfl/XFLConverter.java index db037227c..add52bdf6 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/xfl/XFLConverter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/xfl/XFLConverter.java @@ -153,7 +153,7 @@ public class XFLConverter { public static final int KEY_MODE_SHAPE_TWEEN = 17922; public static final int KEY_MODE_MOTION_TWEEN = 8195; public static final int KEY_MODE_SHAPE_LAYERS = 8192; - + private static final Random random = new Random(123); // predictable random private XFLConverter() { @@ -281,9 +281,9 @@ public class XFLConverter { public static String convertFillStyle(MATRIX mat, HashMap characters, FILLSTYLE fs, int shapeNum) { /* todo: use matrix - if (mat == null) { - mat = new MATRIX(); - }*/ + if (mat == null) { + mat = new MATRIX(); + }*/ StringBuilder ret = new StringBuilder(); //ret += ""; switch (fs.fillStyleType) { @@ -3184,7 +3184,7 @@ public class XFLConverter { } return ""; - } + } private static String convertHTMLText(List tags, DefineEditTextTag det, String html) { HTMLTextParser tparser = new HTMLTextParser(tags, det); @@ -3215,7 +3215,7 @@ public class XFLConverter { } private static double twipToPixel(double tw) { - return tw /SWF.unitDivisor; + return tw / SWF.unitDivisor; } private static class HTMLTextParser extends DefaultHandler { diff --git a/libsrc/ffdec_lib/src/com/jpexs/helpers/Cache.java b/libsrc/ffdec_lib/src/com/jpexs/helpers/Cache.java index 792efff94..6ca3d05cd 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/helpers/Cache.java +++ b/libsrc/ffdec_lib/src/com/jpexs/helpers/Cache.java @@ -41,7 +41,7 @@ public class Cache implements Freed { private String name; static { - Runtime.getRuntime().addShutdownHook(new Thread(){ + Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { @@ -50,12 +50,12 @@ public class Cache implements Freed { c.free(); } } - + }); } - - public static Cache getInstance(boolean weak,String name) { - Cache instance = new Cache<>(weak,name); + + public static Cache getInstance(boolean weak, String name) { + Cache instance = new Cache<>(weak, name); instances.add(instance); return instance; } @@ -95,7 +95,7 @@ public class Cache implements Freed { Map newCache = null; if (thisStorageType == STORAGE_FILES) { try { - newCache = new FileHashMap<>(File.createTempFile("ffdec_cache_"+name+"_", ".tmp")); + newCache = new FileHashMap<>(File.createTempFile("ffdec_cache_" + name + "_", ".tmp")); } catch (IOException ex) { thisStorageType = STORAGE_MEMORY; } @@ -113,7 +113,7 @@ public class Cache implements Freed { this.cache = newCache; } - private Cache(boolean weak,String name) { + private Cache(boolean weak, String name) { this.weak = weak; this.name = name; initCache(); @@ -148,8 +148,8 @@ public class Cache implements Freed { @Override public void free() { - if(cache instanceof Freed){ - ((Freed)cache).free(); + if (cache instanceof Freed) { + ((Freed) cache).free(); } } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/helpers/FileHashMap.java b/libsrc/ffdec_lib/src/com/jpexs/helpers/FileHashMap.java index 683dab66f..43f51a1e8 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/helpers/FileHashMap.java +++ b/libsrc/ffdec_lib/src/com/jpexs/helpers/FileHashMap.java @@ -34,8 +34,6 @@ public class FileHashMap extends AbstractMap implements Freed { private int maxGapLen = 0; private boolean deleted = false; - - private static class Gap implements Comparable { public long offset; @@ -111,7 +109,7 @@ public class FileHashMap extends AbstractMap implements Freed { @Override public boolean containsKey(Object key) { - if(deleted){ + if (deleted) { throw new NullPointerException(); } return offsets.containsKey(key); @@ -119,7 +117,7 @@ public class FileHashMap extends AbstractMap implements Freed { @Override public Set keySet() { - if(deleted){ + if (deleted) { throw new NullPointerException(); } return offsets.keySet(); @@ -127,7 +125,7 @@ public class FileHashMap extends AbstractMap implements Freed { @Override public V get(Object key) { - if(deleted){ + if (deleted) { throw new NullPointerException(); } try { @@ -156,7 +154,7 @@ public class FileHashMap extends AbstractMap implements Freed { @Override public synchronized V put(K key, V value) { - if(deleted){ + if (deleted) { throw new NullPointerException(); } ObjectOutputStream oos = null; @@ -222,11 +220,11 @@ public class FileHashMap extends AbstractMap implements Freed { @Override public V remove(Object objKey) { - if(deleted){ + if (deleted) { throw new NullPointerException(); - } + } @SuppressWarnings("unchecked") - K key=(K)objKey; + K key = (K) objKey; if (!containsKey(key)) { return null; } @@ -247,19 +245,19 @@ public class FileHashMap extends AbstractMap implements Freed { @Override public Set> entrySet() { - if(deleted){ + if (deleted) { throw new NullPointerException(); } - Set> ret=new HashSet>(); - for(K key:keySet()){ - ret.add(new FileEntry(this,key)); + Set> ret = new HashSet>(); + for (K key : keySet()) { + ret.add(new FileEntry(this, key)); } return ret; } @Override public void clear() { - if(deleted){ + if (deleted) { throw new NullPointerException(); } offsets.clear(); @@ -271,10 +269,10 @@ public class FileHashMap extends AbstractMap implements Freed { } catch (IOException ex) { Logger.getLogger(FileHashMap.class.getName()).log(Level.SEVERE, null, ex); } - } + } public void delete() { - if(deleted){ + if (deleted) { throw new NullPointerException(); } try { @@ -284,9 +282,9 @@ public class FileHashMap extends AbstractMap implements Freed { } fileName.delete(); deleted = true; - + } - + @Override public boolean isFreeing() { return !deleted; @@ -294,7 +292,7 @@ public class FileHashMap extends AbstractMap implements Freed { @Override public void free() { - if(!deleted){ + if (!deleted) { delete(); } } @@ -308,6 +306,5 @@ public class FileHashMap extends AbstractMap implements Freed { public int size() { return offsets.size(); } - - + } diff --git a/libsrc/ffdec_lib/src/com/jpexs/helpers/Helper.java b/libsrc/ffdec_lib/src/com/jpexs/helpers/Helper.java index 33de9909f..c94c13db3 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/helpers/Helper.java +++ b/libsrc/ffdec_lib/src/com/jpexs/helpers/Helper.java @@ -412,8 +412,7 @@ public class Helper { return ret; } - public static ByteArrayInputStream getInputStream(byte[] - ... data) { + public static ByteArrayInputStream getInputStream(byte[]... data) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { @@ -480,8 +479,7 @@ public class Helper { } } - public static void writeFile(String file, byte[] - ... data) { + public static void writeFile(String file, byte[]... data) { try (FileOutputStream fos = new FileOutputStream(file)) { for (byte[] d : data) { fos.write(d); @@ -874,7 +872,7 @@ public class Helper { } return ret; } - + public static String byteCountStr(long bytes, boolean si) { int unit = si ? 1000 : 1024; if (bytes < unit) { @@ -885,5 +883,4 @@ public class Helper { return String.format("%.1f %sB", bytes / Math.pow(unit, exp), pre); } - } diff --git a/libsrc/ffdec_lib/src/com/jpexs/helpers/Searchable.java b/libsrc/ffdec_lib/src/com/jpexs/helpers/Searchable.java index 597ab365a..a9d932cf0 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/helpers/Searchable.java +++ b/libsrc/ffdec_lib/src/com/jpexs/helpers/Searchable.java @@ -31,17 +31,14 @@ public interface Searchable { * @param data * @return Map Position=>Input stream */ - public Map search(byte[] - - ... data); + public Map search(byte[]... data); /** * Searches for byte sequences with progress listener + * * @param progListener Listener * @param data * @return Map Position=>Input stream */ - public Map search(ProgressListener progListener, byte[] - -... data); + public Map search(ProgressListener progListener, byte[]... data); } diff --git a/libsrc/ffdec_lib/src/com/jpexs/helpers/StreamSearch.java b/libsrc/ffdec_lib/src/com/jpexs/helpers/StreamSearch.java index c04f54a85..3278fc8a1 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/helpers/StreamSearch.java +++ b/libsrc/ffdec_lib/src/com/jpexs/helpers/StreamSearch.java @@ -36,14 +36,12 @@ public class StreamSearch implements Searchable { } @Override - public Map search(byte[] - ... data) { + public Map search(byte[]... data) { return search(null, data); } @Override - public Map search(ProgressListener progListener, byte[] - ... data) { + public Map search(ProgressListener progListener, byte[]... data) { Map ret = new HashMap<>(); int maxFindLen = 0; for (int i = 0; i < data.length; i++) { diff --git a/libsrc/ffdec_lib/src/com/jpexs/helpers/SwfHeaderStreamSearch.java b/libsrc/ffdec_lib/src/com/jpexs/helpers/SwfHeaderStreamSearch.java index 7576a79f4..864b38cb2 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/helpers/SwfHeaderStreamSearch.java +++ b/libsrc/ffdec_lib/src/com/jpexs/helpers/SwfHeaderStreamSearch.java @@ -36,16 +36,14 @@ public class SwfHeaderStreamSearch implements Searchable { } @Override - public Map search(byte[] - ... data) { + public Map search(byte[]... data) { return search(null, data); } @Override - public Map search(ProgressListener progListener, byte[] - ... data) { + public Map search(ProgressListener progListener, byte[]... data) { // Ignore data parameter, find only FWS, CWS, ZWS, GFX and CFX - + Map ret = new HashMap<>(); byte[] buf = is.getAllRead(); byte byte2 = buf[0], byte3 = buf[1]; diff --git a/libsrc/ffdec_lib/src/com/jpexs/helpers/resource/canvas.js b/libsrc/ffdec_lib/src/com/jpexs/helpers/resource/canvas.js index 377f95986..132f312ab 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/helpers/resource/canvas.js +++ b/libsrc/ffdec_lib/src/com/jpexs/helpers/resource/canvas.js @@ -4,7 +4,7 @@ Filters = {}; -var createCanvas = function(width, height) { +var createCanvas = function (width, height) { var c = document.createElement("canvas"); c.width = width; c.height = height; @@ -15,7 +15,7 @@ var createCanvas = function(width, height) { return c; }; -Filters._premultiply = function(data) { +Filters._premultiply = function (data) { var len = data.length; for (var i = 0; i < len; i += 4) { var f = data[i + 3] * 0.003921569; @@ -25,7 +25,7 @@ Filters._premultiply = function(data) { } }; -Filters._unpremultiply = function(data) { +Filters._unpremultiply = function (data) { var len = data.length; for (var i = 0; i < len; i += 4) { var a = data[i + 3]; @@ -53,7 +53,7 @@ Filters._unpremultiply = function(data) { }; -Filters._boxBlurHorizontal = function(pixels, mask, w, h, radius, maskType) { +Filters._boxBlurHorizontal = function (pixels, mask, w, h, radius, maskType) { var index = 0; var newColors = []; @@ -119,7 +119,7 @@ Filters._boxBlurHorizontal = function(pixels, mask, w, h, radius, maskType) { } }; -Filters._boxBlurVertical = function(pixels, mask, w, h, radius, maskType) { +Filters._boxBlurVertical = function (pixels, mask, w, h, radius, maskType) { var newColors = []; var oldPixelOffset = -(radius + 1) * w * 4; var newPixelOffset = (radius) * w * 4; @@ -189,7 +189,7 @@ Filters._boxBlurVertical = function(pixels, mask, w, h, radius, maskType) { }; -Filters.blur = function(canvas, ctx, hRadius, vRadius, iterations, mask, maskType) { +Filters.blur = function (canvas, ctx, hRadius, vRadius, iterations, mask, maskType) { var imgData = ctx.getImageData(0, 0, canvas.width, canvas.height); var data = imgData.data; Filters._premultiply(data); @@ -208,7 +208,7 @@ Filters.blur = function(canvas, ctx, hRadius, vRadius, iterations, mask, maskTyp return retCanvas; } -Filters._moveRGB = function(width, height, rgb, deltaX, deltaY, fill) { +Filters._moveRGB = function (width, height, rgb, deltaX, deltaY, fill) { var img = createCanvas(width, height); var ig = img.getContext("2d"); @@ -230,7 +230,7 @@ Filters.FULL = 1; Filters.INNER = 2; Filters.OUTER = 3; -Filters._setRGB = function(ctx, x, y, width, height, data) { +Filters._setRGB = function (ctx, x, y, width, height, data) { var id = ctx.createImageData(width, height); for (var i = 0; i < data.length; i++) { id.data[i] = data[i]; @@ -238,7 +238,7 @@ Filters._setRGB = function(ctx, x, y, width, height, data) { ctx.putImageData(id, x, y); }; -Filters.gradientGlow = function(srcCanvas, src, blurX, blurY, angle, distance, colors, ratios, type, iterations, strength, knockout) { +Filters.gradientGlow = function (srcCanvas, src, blurX, blurY, angle, distance, colors, ratios, type, iterations, strength, knockout) { var width = canvas.width; var height = canvas.height; var retCanvas = createCanvas(width, height); @@ -322,7 +322,7 @@ Filters.gradientGlow = function(srcCanvas, src, blurX, blurY, angle, distance, c -Filters.dropShadow = function(canvas, src, blurX, blurY, angle, distance, color, inner, iterations, strength, knockout) { +Filters.dropShadow = function (canvas, src, blurX, blurY, angle, distance, color, inner, iterations, strength, knockout) { var width = canvas.width; var height = canvas.height; var srcPixels = src.getImageData(0, 0, width, height).data; @@ -374,7 +374,7 @@ Filters.dropShadow = function(canvas, src, blurX, blurY, angle, distance, color, return retCanvas; }; -Filters._cut = function(a, min, max) { +Filters._cut = function (a, min, max) { if (a > max) a = max; if (a < min) @@ -382,7 +382,7 @@ Filters._cut = function(a, min, max) { return a; } -Filters.gradientBevel = function(canvas, src, colors, ratios, blurX, blurY, strength, type, angle, distance, knockout, iterations) { +Filters.gradientBevel = function (canvas, src, colors, ratios, blurX, blurY, strength, type, angle, distance, knockout, iterations) { var width = canvas.width; var height = canvas.height; var retImg = createCanvas(width, height); @@ -497,7 +497,7 @@ Filters.gradientBevel = function(canvas, src, colors, ratios, blurX, blurY, stre } return retImg; } -Filters.bevel = function(canvas, src, blurX, blurY, strength, type, highlightColor, shadowColor, angle, distance, knockout, iterations) { +Filters.bevel = function (canvas, src, blurX, blurY, strength, type, highlightColor, shadowColor, angle, distance, knockout, iterations) { return Filters.gradientBevel(canvas, src, [ shadowColor, [shadowColor[0], shadowColor[1], shadowColor[2], 0], @@ -510,7 +510,7 @@ Filters.bevel = function(canvas, src, blurX, blurY, strength, type, highlightCol //http://www.html5rocks.com/en/tutorials/canvas/imagefilters/ -Filters.convolution = function(canvas, ctx, weights, opaque) { +Filters.convolution = function (canvas, ctx, weights, opaque) { var pixels = ctx.getImageData(0, 0, canvas.width, canvas.height); var side = Math.round(Math.sqrt(weights.length)); var halfSide = Math.floor(side / 2); @@ -558,7 +558,7 @@ Filters.convolution = function(canvas, ctx, weights, opaque) { return outCanvas; }; -Filters.colorMatrix = function(canvas, ctx, m) { +Filters.colorMatrix = function (canvas, ctx, m) { var pixels = ctx.getImageData(0, 0, canvas.width, canvas.height); var data = pixels.data; @@ -586,14 +586,14 @@ Filters.colorMatrix = function(canvas, ctx, m) { }; -Filters.glow = function(canvas, src, blurX, blurY, strength, color, inner, knockout, iterations) { +Filters.glow = function (canvas, src, blurX, blurY, strength, color, inner, knockout, iterations) { return Filters.dropShadow(canvas, src, blurX, blurY, 45, 0, color, inner, iterations, strength, knockout); }; var BlendModes = {}; -BlendModes._cut = function(v) { +BlendModes._cut = function (v) { if (v < 0) v = 0; if (v > 255) @@ -601,7 +601,7 @@ BlendModes._cut = function(v) { return v; }; -BlendModes.normal = function(src, dst, result, pos) { +BlendModes.normal = function (src, dst, result, pos) { var am = (255 - src[pos + 3]) / 255; result[pos] = this._cut(src[pos] * src[pos + 3] / 255 + dst[pos] * dst[pos + 3] / 255 * am); result[pos + 1] = this._cut(src[pos + 1] * src[pos + 3] / 255 + dst[pos + 1] * dst[pos + 3] / 255 * am); @@ -609,81 +609,81 @@ BlendModes.normal = function(src, dst, result, pos) { result[pos + 3] = this._cut(src[pos + 3] + dst[pos + 3] * am); }; -BlendModes.layer = function(src, dst, result, pos) { +BlendModes.layer = function (src, dst, result, pos) { BlendModes.normal(src, dst, result, pos); }; -BlendModes.multiply = function(src, dst, result, pos) { +BlendModes.multiply = function (src, dst, result, pos) { result[pos + 0] = (src[pos + 0] * dst[pos + 0]) >> 8; result[pos + 1] = (src[pos + 1] * dst[pos + 1]) >> 8; result[pos + 2] = (src[pos + 2] * dst[pos + 2]) >> 8; result[pos + 3] = Math.min(255, src[pos + 3] + dst[pos + 3] - (src[pos + 3] * dst[pos + 3]) / 255); }; -BlendModes.screen = function(src, dst, result, pos) { +BlendModes.screen = function (src, dst, result, pos) { result[pos + 0] = 255 - ((255 - src[pos + 0]) * (255 - dst[pos + 0]) >> 8); result[pos + 1] = 255 - ((255 - src[pos + 1]) * (255 - dst[pos + 1]) >> 8); result[pos + 2] = 255 - ((255 - src[pos + 2]) * (255 - dst[pos + 2]) >> 8); result[pos + 3] = Math.min(255, src[pos + 3] + dst[pos + 3] - (src[pos + 3] * dst[pos + 3]) / 255); }; -BlendModes.lighten = function(src, dst, result, pos) { +BlendModes.lighten = function (src, dst, result, pos) { result[pos + 0] = Math.max(src[pos + 0], dst[pos + 0]); result[pos + 1] = Math.max(src[pos + 1], dst[pos + 1]); result[pos + 2] = Math.max(src[pos + 2], dst[pos + 2]); result[pos + 3] = Math.min(255, src[pos + 3] + dst[pos + 3] - (src[pos + 3] * dst[pos + 3]) / 255); }; -BlendModes.darken = function(src, dst, result, pos) { +BlendModes.darken = function (src, dst, result, pos) { result[pos + 0] = Math.min(src[pos + 0], dst[pos + 0]); result[pos + 1] = Math.min(src[pos + 1], dst[pos + 1]); result[pos + 2] = Math.min(src[pos + 2], dst[pos + 2]); result[pos + 3] = Math.min(255, src[pos + 3] + dst[pos + 3] - (src[pos + 3] * dst[pos + 3]) / 255); }; -BlendModes.difference = function(src, dst, result, pos) { +BlendModes.difference = function (src, dst, result, pos) { result[pos + 0] = Math.abs(dst[pos + 0] - src[pos + 0]); result[pos + 1] = Math.abs(dst[pos + 1] - src[pos + 1]); result[pos + 2] = Math.abs(dst[pos + 2] - src[pos + 2]); result[pos + 3] = Math.min(255, src[pos + 3] + dst[pos + 3] - (src[pos + 3] * dst[pos + 3]) / 255); }; -BlendModes.add = function(src, dst, result, pos) { +BlendModes.add = function (src, dst, result, pos) { result[pos + 0] = Math.min(255, src[pos + 0] + dst[pos + 0]); result[pos + 1] = Math.min(255, src[pos + 1] + dst[pos + 1]); result[pos + 2] = Math.min(255, src[pos + 2] + dst[pos + 2]); result[pos + 3] = Math.min(255, src[pos + 3] + dst[pos + 3]); }; -BlendModes.subtract = function(src, dst, result, pos) { +BlendModes.subtract = function (src, dst, result, pos) { result[pos + 0] = Math.max(0, src[pos + 0] + dst[pos + 0] - 256); result[pos + 1] = Math.max(0, src[pos + 1] + dst[pos + 1] - 256); result[pos + 2] = Math.max(0, src[pos + 2] + dst[pos + 2] - 256); result[pos + 3] = Math.min(255, src[pos + 3] + dst[pos + 3] - (src[pos + 3] * dst[pos + 3]) / 255); }; -BlendModes.invert = function(src, dst, result, pos) { +BlendModes.invert = function (src, dst, result, pos) { result[pos + 0] = 255 - dst[pos + 0]; result[pos + 1] = 255 - dst[pos + 1]; result[pos + 2] = 255 - dst[pos + 2]; result[pos + 3] = src[pos + 3]; }; -BlendModes.alpha = function(src, dst, result, pos) { +BlendModes.alpha = function (src, dst, result, pos) { result[pos + 0] = src[pos + 0]; result[pos + 1] = src[pos + 1]; result[pos + 2] = src[pos + 2]; result[pos + 3] = dst[pos + 3]; //? }; -BlendModes.erase = function(src, dst, result, pos) { +BlendModes.erase = function (src, dst, result, pos) { result[pos + 0] = src[pos + 0]; result[pos + 1] = src[pos + 1]; result[pos + 2] = src[pos + 2]; result[pos + 3] = 255 - dst[pos + 3]; //? }; -BlendModes.overlay = function(src, dst, result, pos) { +BlendModes.overlay = function (src, dst, result, pos) { result[pos + 0] = dst[pos + 0] < 128 ? dst[pos + 0] * src[pos + 0] >> 7 : 255 - ((255 - dst[pos + 0]) * (255 - src[pos + 0]) >> 7); result[pos + 1] = dst[pos + 1] < 128 ? dst[pos + 1] * src[pos + 1] >> 7 @@ -693,7 +693,7 @@ BlendModes.overlay = function(src, dst, result, pos) { result[pos + 3] = Math.min(255, src[pos + 3] + dst[pos + 3] - (src[pos + 3] * dst[pos + 3]) / 255); }; -BlendModes.hardlight = function(src, dst, result, pos) { +BlendModes.hardlight = function (src, dst, result, pos) { result[pos + 0] = src[pos + 0] < 128 ? dst[pos + 0] * src[pos + 0] >> 7 : 255 - ((255 - src[pos + 0]) * (255 - dst[pos + 0]) >> 7); result[pos + 1] = src[pos + 1] < 128 ? dst[pos + 1] * src[pos + 1] >> 7 @@ -721,7 +721,7 @@ BlendModes._list = [ BlendModes.hardlight ]; -BlendModes.blendData = function(srcPixel, dstPixel, retData, modeIndex) { +BlendModes.blendData = function (srcPixel, dstPixel, retData, modeIndex) { var result = []; var retPixel = []; var alpha = 1.0; @@ -741,7 +741,7 @@ BlendModes.blendData = function(srcPixel, dstPixel, retData, modeIndex) { } }; -BlendModes.blendCanvas = function(src, dst, result, modeIndex) { +BlendModes.blendCanvas = function (src, dst, result, modeIndex) { var width = src.width; var height = src.height; var rctx = result.getContext("2d"); @@ -776,7 +776,7 @@ function concatMatrix(m1, m2) { } -var enhanceContext = function(context) { +var enhanceContext = function (context) { var m = [1, 0, 0, 1, 0, 0]; context._matrix = m; @@ -785,42 +785,42 @@ var enhanceContext = function(context) { var super_ = context.__proto__; context.__proto__ = ({ - save: function() { + save: function () { this._savedMatrices.push(this._matrix); //.slice() super_.save.call(this); }, //if the stack of matrices we're managing doesn't have a saved matrix, //we won't even call the context's original `restore` method. - restore: function() { + restore: function () { if (this._savedMatrices.length == 0) return; super_.restore.call(this); this._matrix = this._savedMatrices.pop(); }, - scale: function(x, y) { + scale: function (x, y) { super_.scale.call(this, x, y); }, - rotate: function(theta) { + rotate: function (theta) { super_.rotate.call(this, theta); }, - translate: function(x, y) { + translate: function (x, y) { super_.translate.call(this, x, y); }, - transform: function(a, b, c, d, e, f) { + transform: function (a, b, c, d, e, f) { this._matrix = concatMatrix([a, b, c, d, e, f], this._matrix); super_.transform.call(this, a, b, c, d, e, f); }, - setTransform: function(a, b, c, d, e, f) { + setTransform: function (a, b, c, d, e, f) { this._matrix = [a, b, c, d, e, f]; super_.setTransform.call(this, a, b, c, d, e, f); }, - resetTransform: function() { + resetTransform: function () { super_.resetTransform.call(this); }, - applyTransforms: function(m) { + applyTransforms: function (m) { this.setTransform(m[0], m[1], m[2], m[3], m[4], m[5]) }, - applyTransformToPoint: function(p) { + applyTransformToPoint: function (p) { var ret = {}; ret.x = this._matrix[0] * p.x + this._matrix[2] * p.y + this._matrix[4]; ret.y = this._matrix[1] * p.x + this._matrix[3] * p.y + this._matrix[5]; @@ -831,7 +831,7 @@ var enhanceContext = function(context) { return context; }; -var cxform = function(r_add, g_add, b_add, a_add, r_mult, g_mult, b_mult, a_mult) { +var cxform = function (r_add, g_add, b_add, a_add, r_mult, g_mult, b_mult, a_mult) { this.r_add = r_add; this.g_add = g_add; this.b_add = b_add; @@ -840,14 +840,14 @@ var cxform = function(r_add, g_add, b_add, a_add, r_mult, g_mult, b_mult, a_mult this.g_mult = g_mult; this.b_mult = b_mult; this.a_mult = a_mult; - this._cut = function(v, min, max) { + this._cut = function (v, min, max) { if (v < min) v = min; if (v > max) v = max; return v; }; - this.apply = function(c) { + this.apply = function (c) { var d = c; d[0] = this._cut(Math.round(d[0] * this.r_mult / 255 + this.r_add), 0, 255); d[1] = this._cut(Math.round(d[1] * this.g_mult / 255 + this.g_add), 0, 255); @@ -855,7 +855,7 @@ var cxform = function(r_add, g_add, b_add, a_add, r_mult, g_mult, b_mult, a_mult d[3] = this._cut(Math.round(d[3] * this.a_mult / 255 + this.a_add / 255), 0, 1); return d; }; - this.applyToImage = function(fimg) { + this.applyToImage = function (fimg) { if (this.isEmpty()) { return fimg } @@ -875,15 +875,15 @@ var cxform = function(r_add, g_add, b_add, a_add, r_mult, g_mult, b_mult, a_mult ictx.putImageData(imdata, 0, 0); return icanvas; }; - this.merge = function(cx) { + this.merge = function (cx) { return new cxform(this.r_add + cx.r_add, this.g_add + cx.g_add, this.b_add + cx.b_add, this.a_add + cx.a_add, this.r_mult * cx.r_mult / 255, this.g_mult * cx.g_mult / 255, this.b_mult * cx.b_mult / 255, this.a_mult * cx.a_mult / 255); }; - this.isEmpty = function() { + this.isEmpty = function () { return this.r_add == 0 && this.g_add == 0 && this.b_add == 0 && this.a_add == 0 && this.r_mult == 255 && this.g_mult == 255 && this.b_mult == 255 && this.a_mult == 255; }; }; -var place = function(obj, canvas, ctx, matrix, ctrans, blendMode, frame, ratio, time) { +var place = function (obj, canvas, ctx, matrix, ctrans, blendMode, frame, ratio, time) { ctx.save(); ctx.transform(matrix[0], matrix[1], matrix[2], matrix[3], matrix[4], matrix[5]); if (blendMode > 1) { @@ -904,14 +904,14 @@ var place = function(obj, canvas, ctx, matrix, ctrans, blendMode, frame, ratio, } ctx.restore(); } -var tocolor = function(c) { +var tocolor = function (c) { var r = "rgba(" + c[0] + "," + c[1] + "," + c[2] + "," + c[3] + ")"; return r; }; -window.addEventListener('load', function() { +window.addEventListener('load', function () { var wsize = document.getElementById("width_size"); var hsize = document.getElementById("height_size"); diff --git a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/RecompileTest.java b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/RecompileTest.java index 6bad12398..4d882d722 100644 --- a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/RecompileTest.java +++ b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/RecompileTest.java @@ -103,8 +103,7 @@ public class RecompileTest { System.out.println("Recompiling:" + en.getKey().toString() + "..."); en.getValue().toSource(htw, swf.abcList, abc.script_info.get(s).traits.traits, ScriptExportMode.AS, false); String original = htw.toString(); - ABC nabc = abc; //new ABC(swf); - com.jpexs.decompiler.flash.abc.avm2.parser.script.ActionScriptParser.compile(original, nabc, allAbcs, false, en.getKey().className + ".as", abc.instance_info.size()); + com.jpexs.decompiler.flash.abc.avm2.parser.script.ActionScriptParser.compile(original, abc, allAbcs, false, en.getKey().className + ".as", abc.instance_info.size()); //remove last compiled script: abc.script_info.remove(abc.script_info.size()-1); } diff --git a/src/com/jpexs/decompiler/flash/gui/FolderPreviewPanel.java b/src/com/jpexs/decompiler/flash/gui/FolderPreviewPanel.java index 92c6b9a7c..0461193b3 100644 --- a/src/com/jpexs/decompiler/flash/gui/FolderPreviewPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/FolderPreviewPanel.java @@ -78,7 +78,7 @@ public class FolderPreviewPanel extends JPanel { public FolderPreviewPanel(final MainPanel mainPanel, List items) { this.items = items; - cachedPreviews = Cache.getInstance(false,"preview"); + cachedPreviews = Cache.getInstance(false, "preview"); addMouseListener(new MouseAdapter() { diff --git a/src/com/jpexs/decompiler/flash/gui/ImagePanel.java b/src/com/jpexs/decompiler/flash/gui/ImagePanel.java index ec7112d9f..2c5f1851a 100644 --- a/src/com/jpexs/decompiler/flash/gui/ImagePanel.java +++ b/src/com/jpexs/decompiler/flash/gui/ImagePanel.java @@ -736,7 +736,7 @@ public final class ImagePanel extends JPanel implements ActionListener, MediaDis if (frame >= timeline.getFrameCount()) { return; } - if(frame<0){ + if (frame < 0) { return; } this.frame = frame; diff --git a/src/com/jpexs/decompiler/flash/gui/MainPanel.java b/src/com/jpexs/decompiler/flash/gui/MainPanel.java index 53d7fdb64..66baed381 100644 --- a/src/com/jpexs/decompiler/flash/gui/MainPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/MainPanel.java @@ -26,6 +26,7 @@ import com.jpexs.decompiler.flash.abc.ScriptPack; import com.jpexs.decompiler.flash.abc.types.traits.Trait; import com.jpexs.decompiler.flash.abc.types.traits.TraitClass; import com.jpexs.decompiler.flash.configuration.Configuration; +import com.jpexs.decompiler.flash.configuration.ConfigurationItem; import com.jpexs.decompiler.flash.dumpview.DumpInfo; import com.jpexs.decompiler.flash.dumpview.DumpInfoSwfNode; import com.jpexs.decompiler.flash.exporters.BinaryDataExporter; @@ -71,6 +72,7 @@ import com.jpexs.decompiler.flash.helpers.Freed; import com.jpexs.decompiler.flash.importers.BinaryDataImporter; import com.jpexs.decompiler.flash.importers.ImageImporter; import com.jpexs.decompiler.flash.importers.ShapeImporter; +import com.jpexs.decompiler.flash.importers.TextImporter; import com.jpexs.decompiler.flash.tags.ABCContainerTag; import com.jpexs.decompiler.flash.tags.DefineBinaryDataTag; import com.jpexs.decompiler.flash.tags.DefineSoundTag; @@ -90,6 +92,7 @@ import com.jpexs.decompiler.flash.tags.base.MorphShapeTag; import com.jpexs.decompiler.flash.tags.base.ShapeTag; import com.jpexs.decompiler.flash.tags.base.SoundStreamHeadTypeTag; import com.jpexs.decompiler.flash.tags.base.SoundTag; +import com.jpexs.decompiler.flash.tags.base.TextImportErrorHandler; import com.jpexs.decompiler.flash.tags.base.TextTag; import com.jpexs.decompiler.flash.tags.text.TextParseException; import com.jpexs.decompiler.flash.timeline.DepthState; @@ -141,7 +144,6 @@ import java.beans.PropertyChangeListener; import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileInputStream; -import java.io.FilenameFilter; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; @@ -1372,125 +1374,6 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec } } - private Map splitTextRecords(String texts) { - String[] textsArr = texts.split(Helper.newLine + Configuration.textExportSingleFileSeparator.get() + Helper.newLine); - String recordSeparator = Helper.newLine + Configuration.textExportSingleFileRecordSeparator.get() + Helper.newLine; - Map result = new HashMap<>(); - for (String text : textsArr) { - String[] textArr = text.split(Helper.newLine, 2); - String idLine = textArr[0]; - if (idLine.startsWith("ID:")) { - int id = Integer.parseInt(idLine.substring(3).trim()); - String[] records = textArr[1].split(recordSeparator); - result.put(id, records); - } else { - if (View.showConfirmDialog(this, translate("error.text.import"), translate("error"), JOptionPane.OK_CANCEL_OPTION) == JOptionPane.CANCEL_OPTION) { - return null; - } - } - } - return result; - } - - private void importTextsSingleFile(File textsFile, SWF swf) { - String texts = Helper.readTextFile(textsFile.getPath()); - Map records = splitTextRecords(texts); - if (records != null) { - for (int characterId : records.keySet()) { - for (Tag tag : swf.tags) { - if (tag instanceof TextTag) { - TextTag textTag = (TextTag) tag; - if (textTag.getCharacterId() == characterId) { - String[] currentRecords = records.get(characterId); - String text = textTag.getFormattedText(); - if (!saveText(textTag, text, currentRecords)) { - if (View.showConfirmDialog(this, translate("error.text.import"), translate("error"), JOptionPane.OK_CANCEL_OPTION) == JOptionPane.CANCEL_OPTION) { - return; - } - } - break; - } - } - } - } - } - } - - private void importTextsSingleFileFormatted(File textsFile, SWF swf) { - String texts = Helper.readTextFile(textsFile.getPath()); - Map records = splitTextRecords(texts); - if (records != null) { - for (int characterId : records.keySet()) { - for (Tag tag : swf.tags) { - if (tag instanceof TextTag) { - TextTag textTag = (TextTag) tag; - if (textTag.getCharacterId() == characterId) { - String[] currentRecords = records.get(characterId); - if (!saveText(textTag, currentRecords[0], null)) { - if (View.showConfirmDialog(this, translate("error.text.import"), translate("error"), JOptionPane.OK_CANCEL_OPTION) == JOptionPane.CANCEL_OPTION) { - return; - } - } - break; - } - } - } - } - } - } - - private void importTextsMultipleFiles(String folder, SWF swf) { - File textsFolder = new File(Path.combine(folder, TextExporter.TEXT_EXPORT_FOLDER)); - String[] files = textsFolder.list(new FilenameFilter() { - - private final Pattern pat = Pattern.compile("\\d+\\.txt", Pattern.CASE_INSENSITIVE); - - @Override - public boolean accept(File dir, String name) { - - return pat.matcher(name).matches(); - } - }); - - for (String fileName : files) { - String texts = Helper.readTextFile(Path.combine(textsFolder.getPath(), fileName)); - int characterId = Integer.parseInt(fileName.split("\\.")[0]); - String recordSeparator = Helper.newLine + Configuration.textExportSingleFileRecordSeparator.get() + Helper.newLine; - boolean formatted = !texts.contains(recordSeparator) && texts.startsWith("[" + Helper.newLine); - if (!formatted) { - String[] records = texts.split(recordSeparator); - for (Tag tag : swf.tags) { - if (tag instanceof TextTag) { - TextTag textTag = (TextTag) tag; - if (textTag.getCharacterId() == characterId) { - String text = textTag.getFormattedText(); - if (!saveText(textTag, text, records)) { - if (View.showConfirmDialog(this, translate("error.text.import"), translate("error"), JOptionPane.OK_CANCEL_OPTION) == JOptionPane.CANCEL_OPTION) { - return; - } - } - break; - } - } - } - } else { - for (Tag tag : swf.tags) { - if (tag instanceof TextTag) { - TextTag textTag = (TextTag) tag; - if (textTag.getCharacterId() == characterId) { - if (!saveText(textTag, texts, null)) { - if (View.showConfirmDialog(this, translate("error.text.import"), translate("error"), JOptionPane.OK_CANCEL_OPTION) == JOptionPane.CANCEL_OPTION) { - return; - } - } - break; - } - } - } - } - } - } - public void importText(final SWF swf) { JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(new File(Configuration.lastExportDir.get())); @@ -1500,16 +1383,38 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { String selFile = Helper.fixDialogFile(chooser.getSelectedFile()).getAbsolutePath(); File textsFile = new File(Path.combine(selFile, TextExporter.TEXT_EXPORT_FOLDER, TextExporter.TEXT_EXPORT_FILENAME_FORMATTED)); + final MainPanel diz = this; + TextImporter textImporter = new TextImporter(getMissingCharacterHandler(), new TextImportErrorHandler() { + + // "configuration items" for the current replace only + private final ConfigurationItem doNotShowImportError = new ConfigurationItem<>("doNotShowImportError", true, true); + private final ConfigurationItem doNotShowInvalidText = new ConfigurationItem<>("doNotShowInvalidText", true, true); + + @Override + public boolean handle() { + String msg = translate("error.text.import"); + logger.log(Level.SEVERE, msg); + return View.showConfirmDialog(diz, msg, translate("error"), JOptionPane.OK_CANCEL_OPTION, doNotShowImportError, JOptionPane.OK_OPTION) == JOptionPane.CANCEL_OPTION; + } + + @Override + public boolean handle(String message, long line) { + String msg = translate("error.text.invalid.continue").replace("%text%", message).replace("%line%", Long.toString(line)); + logger.log(Level.SEVERE, msg); + return View.showConfirmDialog(diz, msg, translate("error"), JOptionPane.OK_CANCEL_OPTION, doNotShowInvalidText, JOptionPane.OK_OPTION) == JOptionPane.CANCEL_OPTION; + } + }); + // try to import formatted texts if (textsFile.exists()) { - importTextsSingleFileFormatted(textsFile, swf); + textImporter.importTextsSingleFileFormatted(textsFile, swf); } else { textsFile = new File(Path.combine(selFile, TextExporter.TEXT_EXPORT_FOLDER, TextExporter.TEXT_EXPORT_FILENAME_PLAIN)); // try to import plain texts if (textsFile.exists()) { - importTextsSingleFile(textsFile, swf); + textImporter.importTextsSingleFile(textsFile, swf); } else { - importTextsMultipleFiles(selFile, swf); + textImporter.importTextsMultipleFiles(selFile, swf); } } @@ -1806,31 +1711,35 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec updateClassesList(); } + private MissingCharacterHandler getMissingCharacterHandler() { + return new MissingCharacterHandler() { + @Override + public boolean handle(FontTag font, char character) { + String fontName = font.getSwf().sourceFontNamesMap.get(font.getFontId()); + if (fontName == null) { + fontName = font.getFontName(); + } + Font f = FontTag.installedFontsByName.get(fontName); + if (f == null || !f.canDisplay(character)) { + View.showMessageDialog(null, translate("error.font.nocharacter").replace("%char%", "" + character), translate("error"), JOptionPane.ERROR_MESSAGE); + return false; + } + font.addCharacter(character, f); + return true; + + } + }; + } + public boolean saveText(TextTag textTag, String formattedText, String[] texts) { try { - if (textTag.setFormattedText(new MissingCharacterHandler() { - @Override - public boolean handle(FontTag font, char character) { - String fontName = font.getSwf().sourceFontNamesMap.get(font.getFontId()); - if (fontName == null) { - fontName = font.getFontName(); - } - Font f = FontTag.installedFontsByName.get(fontName); - if (f == null || !f.canDisplay(character)) { - View.showMessageDialog(null, translate("error.font.nocharacter").replace("%char%", "" + character), translate("error"), JOptionPane.ERROR_MESSAGE); - return false; - } - font.addCharacter(character, f); - return true; - - } - }, formattedText, texts)) { - textTag.setModified(true); + if (textTag.setFormattedText(getMissingCharacterHandler(), formattedText, texts)) { return true; } } catch (TextParseException ex) { View.showMessageDialog(null, translate("error.text.invalid").replace("%text%", ex.text).replace("%line%", Long.toString(ex.line)), translate("error"), JOptionPane.ERROR_MESSAGE); } + return false; } diff --git a/src/com/jpexs/decompiler/flash/gui/PreviewPanel.java b/src/com/jpexs/decompiler/flash/gui/PreviewPanel.java index 77b612617..02eb03550 100644 --- a/src/com/jpexs/decompiler/flash/gui/PreviewPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/PreviewPanel.java @@ -155,20 +155,20 @@ public class PreviewPanel extends JSplitPane implements ActionListener { super(JSplitPane.HORIZONTAL_SPLIT); this.mainPanel = mainPanel; this.flashPanel = flashPanel; - - Runtime.getRuntime().addShutdownHook(new Thread(){ + + Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { - if(tempFile!=null){ - try{ + if (tempFile != null) { + try { tempFile.delete(); - }catch(Exception ex){ - + } catch (Exception ex) { + } } } - + }); addPropertyChangeListener(JSplitPane.DIVIDER_LOCATION_PROPERTY, new PropertyChangeListener() { @@ -952,7 +952,7 @@ public class PreviewPanel extends JSplitPane implements ActionListener { tempFile.delete(); } try { - tempFile = File.createTempFile("ffdec_view_", ".swf"); + tempFile = File.createTempFile("ffdec_view_", ".swf"); swf.saveTo(new BufferedOutputStream(new FileOutputStream(tempFile))); flashPanel.displaySWF(tempFile.getAbsolutePath(), backgroundColor, swf.frameRate); } catch (IOException iex) { diff --git a/src/com/jpexs/decompiler/flash/gui/View.java b/src/com/jpexs/decompiler/flash/gui/View.java index 4a9b21154..bfa1c3a19 100644 --- a/src/com/jpexs/decompiler/flash/gui/View.java +++ b/src/com/jpexs/decompiler/flash/gui/View.java @@ -382,6 +382,10 @@ public class View { return ret[0]; } + public static int showConfirmDialog(final Component parentComponent, String message, final String title, final int optionType, ConfigurationItem showAgainConfig, int defaultOption) { + return showConfirmDialog(parentComponent, message, title, optionType, JOptionPane.PLAIN_MESSAGE, showAgainConfig, defaultOption); + } + public static int showConfirmDialog(final Component parentComponent, String message, final String title, final int optionType, final int messageTyp, ConfigurationItem showAgainConfig, int defaultOption) { JLabel warLabel = new JLabel("" + message.replace("\r\n", "
") + ""); diff --git a/src/com/jpexs/decompiler/flash/gui/locales/MainFrame.properties b/src/com/jpexs/decompiler/flash/gui/locales/MainFrame.properties index 23aaddfda..3e010dc6a 100644 --- a/src/com/jpexs/decompiler/flash/gui/locales/MainFrame.properties +++ b/src/com/jpexs/decompiler/flash/gui/locales/MainFrame.properties @@ -535,4 +535,6 @@ preview.gotoframe = Goto frame... preview.gotoframe.dialog.title = Goto frame preview.gotoframe.dialog.message = Enter frame number (%min% - %max%) -preview.gotoframe.dialog.frame.error = Invalid frame number. It must be number between %min% and %max%. \ No newline at end of file +preview.gotoframe.dialog.frame.error = Invalid frame number. It must be number between %min% and %max%. + +error.text.invalid.continue = Invalid text: %text% on line %line%. Do you want to continue? diff --git a/src/com/jpexs/decompiler/flash/gui/player/FlashPlayerPanel.java b/src/com/jpexs/decompiler/flash/gui/player/FlashPlayerPanel.java index 4664cd752..5f481ffe4 100644 --- a/src/com/jpexs/decompiler/flash/gui/player/FlashPlayerPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/player/FlashPlayerPanel.java @@ -137,7 +137,7 @@ public class FlashPlayerPanel extends Panel implements Closeable, MediaDisplay { } } } - }); + }); } public synchronized void stopSWF() { @@ -193,16 +193,16 @@ public class FlashPlayerPanel extends Panel implements Closeable, MediaDisplay { } @Override - public boolean isPlaying() { + public boolean isPlaying() { return flash.IsPlaying(); } @Override public void gotoFrame(int frame) { - if(frame<0){ + if (frame < 0) { return; } - if(frame>=getTotalFrames()){ + if (frame >= getTotalFrames()) { return; } flash.GotoFrame(frame); diff --git a/src/com/jpexs/decompiler/flash/gui/player/PlayerControls.java b/src/com/jpexs/decompiler/flash/gui/player/PlayerControls.java index 043a9416c..d77f60875 100644 --- a/src/com/jpexs/decompiler/flash/gui/player/PlayerControls.java +++ b/src/com/jpexs/decompiler/flash/gui/player/PlayerControls.java @@ -35,8 +35,6 @@ import java.awt.datatransfer.Transferable; import java.awt.datatransfer.UnsupportedFlavorException; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -import java.awt.event.ComponentAdapter; -import java.awt.event.ComponentEvent; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.event.MouseMotionAdapter; @@ -48,7 +46,6 @@ import java.util.HashMap; import java.util.Map; import java.util.Timer; import java.util.TimerTask; -import javax.swing.Box; import javax.swing.BoxLayout; import javax.swing.Icon; import javax.swing.JButton; @@ -169,7 +166,6 @@ public class PlayerControls extends JPanel implements ActionListener { add(graphicControls); graphicControls.setVisible(display.screenAvailable()); - playbackControls = new JPanel(); this.display = display; @@ -186,7 +182,7 @@ public class PlayerControls extends JPanel implements ActionListener { }); frameLabel.setVisible(display.screenAvailable()); - + Dimension min = new Dimension(frameLabel.getFontMetrics(notUnderlinedFont).stringWidth("000"), frameLabel.getPreferredSize().height); frameLabel.setMinimumSize(min); frameLabel.setPreferredSize(min); @@ -215,12 +211,11 @@ public class PlayerControls extends JPanel implements ActionListener { timeLabel = new JLabel("(00:00.00)"); totalTimeLabel = new JLabel("(00:00.00)"); totalFrameLabel = new JLabel("0"); - + totalFrameLabel.setVisible(display.screenAvailable()); - - frameControls = new JPanel(new FlowLayout()); - + frameControls = new JPanel(new FlowLayout()); + JButton prevFrameButton = new JButton(View.getIcon("prevframe16")); prevFrameButton.setToolTipText(AppStrings.translate("preview.prevframe")); prevFrameButton.setMargin(new Insets(4, 2, 2, 2)); @@ -229,16 +224,15 @@ public class PlayerControls extends JPanel implements ActionListener { frameControls.add(prevFrameButton); frameControls.setVisible(display.screenAvailable()); - frameControls.add(frameLabel); - + JButton nextFrameButton = new JButton(View.getIcon("nextframe16")); nextFrameButton.setToolTipText(AppStrings.translate("preview.nextframe")); nextFrameButton.setMargin(new Insets(4, 2, 2, 2)); nextFrameButton.setActionCommand(ACTION_NEXTFRAME); nextFrameButton.addActionListener(this); frameControls.add(nextFrameButton); - + JButton gotoFrameButton = new JButton(View.getIcon("gotoframe16")); gotoFrameButton.setToolTipText(AppStrings.translate("preview.gotoframe")); gotoFrameButton.setMargin(new Insets(4, 2, 2, 2)); @@ -246,7 +240,6 @@ public class PlayerControls extends JPanel implements ActionListener { gotoFrameButton.addActionListener(this); frameControls.add(gotoFrameButton); - JPanel currentPanel = new JPanel(new FlowLayout()); currentPanel.add(frameControls); currentPanel.add(timeLabel); @@ -259,7 +252,6 @@ public class PlayerControls extends JPanel implements ActionListener { playbackControls.setLayout(new BoxLayout(playbackControls, BoxLayout.Y_AXIS)); JPanel buttonsPanel = new JPanel(new FlowLayout()); - pauseButton = new JButton(pauseIcon); pauseButton.setToolTipText(AppStrings.translate("preview.pause")); pauseButton.setMargin(new Insets(4, 2, 2, 2)); @@ -271,7 +263,7 @@ public class PlayerControls extends JPanel implements ActionListener { stopButton.setActionCommand(ACTION_STOP); stopButton.addActionListener(this); buttonsPanel.add(pauseButton); - buttonsPanel.add(stopButton); + buttonsPanel.add(stopButton); controlPanel.add(buttonsPanel, BorderLayout.CENTER); progress = new JProgressBar();