From 9f20bd9f8cb1a9568f5e545ef26348a005f833bc Mon Sep 17 00:00:00 2001 From: Honfika Date: Sat, 8 Feb 2014 21:35:54 +0100 Subject: [PATCH] tag editor fixes --- .../jpexs/decompiler/flash/action/Action.java | 1 + .../flash/action/ActionListReader.java | 1 + .../flash/gui/FontPreviewDialog.java | 1 + .../decompiler/flash/gui/GenericTagPanel.java | 29 ++++++++-------- .../gui/generictageditors/NumberEditor.java | 16 +++++++-- .../flash/tags/DefineButtonTag.java | 1 + .../decompiler/flash/tags/DoActionTag.java | 1 + .../flash/tags/DoInitActionTag.java | 1 + .../decompiler/flash/tags/base/ASMSource.java | 1 + .../flash/types/BUTTONCONDACTION.java | 1 + .../flash/types/CLIPACTIONRECORD.java | 1 + .../jpexs/decompiler/flash/types/CXFORM.java | 2 ++ .../flash/types/CXFORMWITHALPHA.java | 2 ++ .../jpexs/decompiler/flash/types/MATRIX.java | 4 +++ .../jpexs/decompiler/flash/types/RECT.java | 2 ++ .../flash/types/annotations/Calculated.java | 33 +++++++++++++++++++ .../types/shaperecords/CurvedEdgeRecord.java | 2 ++ .../shaperecords/StraightEdgeRecord.java | 3 ++ .../types/shaperecords/StyleChangeRecord.java | 4 +++ .../src/com/sun/jna/platform/win32/WinNT.java | 1 + .../com/sun/jna/platform/win32/WinUser.java | 1 + 21 files changed, 90 insertions(+), 18 deletions(-) create mode 100644 trunk/src/com/jpexs/decompiler/flash/types/annotations/Calculated.java diff --git a/trunk/src/com/jpexs/decompiler/flash/action/Action.java b/trunk/src/com/jpexs/decompiler/flash/action/Action.java index a252e9438..c84a7af2a 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/Action.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/Action.java @@ -706,6 +706,7 @@ public class Action implements GraphSourceItem { /** * Converts list of actions to ActionScript source code * + * @param asm * @param actions List of actions * @param version SWF version * @param path diff --git a/trunk/src/com/jpexs/decompiler/flash/action/ActionListReader.java b/trunk/src/com/jpexs/decompiler/flash/action/ActionListReader.java index 1afa175bc..1257a365c 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/ActionListReader.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/ActionListReader.java @@ -529,6 +529,7 @@ public class ActionListReader { * * @param actions * @param index + * @param version * @param removeWhenLast * @return */ diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/FontPreviewDialog.java b/trunk/src/com/jpexs/decompiler/flash/gui/FontPreviewDialog.java index ce2b0b247..bade74248 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/FontPreviewDialog.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/FontPreviewDialog.java @@ -37,6 +37,7 @@ public class FontPreviewDialog extends AppDialog { /** * Creates new form FontPreviewDialog + * @param parent * @param font * @param modal */ diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/GenericTagPanel.java b/trunk/src/com/jpexs/decompiler/flash/gui/GenericTagPanel.java index ecd9803b6..ffdadbe9f 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/GenericTagPanel.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/GenericTagPanel.java @@ -23,10 +23,7 @@ import com.jpexs.decompiler.flash.gui.generictageditors.StringEditor; import com.jpexs.decompiler.flash.gui.helpers.SpringUtilities; import com.jpexs.decompiler.flash.helpers.GraphTextWriter; import com.jpexs.decompiler.flash.tags.Tag; -import com.jpexs.decompiler.flash.types.RECT; -import com.jpexs.decompiler.flash.types.RGB; -import com.jpexs.decompiler.flash.types.ZONEDATA; -import com.jpexs.decompiler.flash.types.ZONERECORD; +import com.jpexs.decompiler.flash.types.annotations.Calculated; import com.jpexs.decompiler.flash.types.annotations.SWFType; import java.awt.BorderLayout; import java.awt.Component; @@ -40,7 +37,6 @@ import javax.swing.JEditorPane; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JScrollPane; -import javax.swing.JTextArea; import javax.swing.SpringLayout; /** @@ -133,6 +129,9 @@ public class GenericTagPanel extends JPanel { } private int generateEditControlsRecursive(Object obj, String parent) { + if (obj == null) { + return 0; + } Field[] fields = obj.getClass().getDeclaredFields(); int propCount = 0; for (Field field : fields) { @@ -169,8 +168,12 @@ public class GenericTagPanel extends JPanel { } private int addEditor(String name, Object obj, Field field, int index, Class type, Object value) throws IllegalArgumentException, IllegalAccessException { - Component editor; + Calculated calculated = field.getAnnotation(Calculated.class); + if (calculated != null) { + return 0; + } SWFType swfType = field.getAnnotation(SWFType.class); + Component editor; if (type.equals(int.class) || type.equals(Integer.class) || type.equals(short.class) || type.equals(Short.class) || type.equals(long.class) || type.equals(Long.class) || @@ -181,17 +184,13 @@ public class GenericTagPanel extends JPanel { editor = new BooleanEditor(obj, field, index, type); } else if (type.equals(String.class)) { editor = new StringEditor(obj, field, index, type); - } else if (type.equals(RECT.class) - || type.equals(RGB.class) - || type.equals(ZONERECORD.class) - || type.equals(ZONEDATA.class)) { - // todo: add other swf releated classes - return generateEditControlsRecursive(value, field.getName() + "."); } else { - JTextArea textArea = new JTextArea(value.toString()); + return generateEditControlsRecursive(value, field.getName() + "."); + /*} else { + JTextArea textArea = new JTextArea(value == null ? "" : value.toString()); textArea.setLineWrap(true); textArea.setEditable(false); - editor = textArea; + editor = textArea;*/ } JLabel label = new JLabel(name + ":", JLabel.TRAILING); @@ -215,7 +214,7 @@ public class GenericTagPanel extends JPanel { } result += "]"; } else if (!swfType.countField().equals("")) { - result += "[" + swfType.count(); + result += "[" + swfType.countField(); if (swfType.countAdd() > 0) { result += " + " + swfType.countAdd(); } diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/generictageditors/NumberEditor.java b/trunk/src/com/jpexs/decompiler/flash/gui/generictageditors/NumberEditor.java index 13427863e..bd53513a4 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/generictageditors/NumberEditor.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/generictageditors/NumberEditor.java @@ -90,7 +90,9 @@ public class NumberEditor extends JSpinner implements GenericTagEditor { case UB: { long max = 1; if (swfType.count() > 0) { - max <<= (swfType.count()); + max <<= swfType.count(); + } else { + max <<= 31; } m = new SpinnerNumberModel((Number) toLong(value), 0L, (long) max - 1, 1L); } @@ -104,12 +106,16 @@ public class NumberEditor extends JSpinner implements GenericTagEditor { m = new SpinnerNumberModel(toInt(value), -0x80, 0x7f, 1); break; case SI16: + case FLOAT16: m = new SpinnerNumberModel(toInt(value), -0x8000, 0x7fff, 1); break; + case FB: case SB: { long max = 1; if (swfType.count() > 0) { max <<= (swfType.count() - 1); + } else { + max <<= 30; } m = new SpinnerNumberModel((Number) toLong(value), (long) (-max), (long) max - 1, 1L); } @@ -117,9 +123,7 @@ public class NumberEditor extends JSpinner implements GenericTagEditor { case SI32: m = new SpinnerNumberModel(toDouble(value), -0x80000000, 0x7fffffff, 1); break; - case FB: case FLOAT: - case FLOAT16: case FIXED: case FIXED8: m = new SpinnerNumberModel(toDouble(value), -0x80000000, 0x7fffffff, 0.01); @@ -149,6 +153,12 @@ public class NumberEditor extends JSpinner implements GenericTagEditor { } private long toLong(Object value) { + if (value instanceof Short) { + return (long) (Short) value; + } + if (value instanceof Integer) { + return (long) (Integer) value; + } if (value instanceof Long) { return (long) (Long) value; } diff --git a/trunk/src/com/jpexs/decompiler/flash/tags/DefineButtonTag.java b/trunk/src/com/jpexs/decompiler/flash/tags/DefineButtonTag.java index c6f25fc76..5de17f8d7 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/DefineButtonTag.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/DefineButtonTag.java @@ -144,6 +144,7 @@ public class DefineButtonTag extends CharacterTag implements ASMSource, BoundedT * * @param version SWF version * @param actions + * @param writer * @return ASM source * @throws java.lang.InterruptedException */ diff --git a/trunk/src/com/jpexs/decompiler/flash/tags/DoActionTag.java b/trunk/src/com/jpexs/decompiler/flash/tags/DoActionTag.java index 924137621..4f81d605e 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/DoActionTag.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/DoActionTag.java @@ -76,6 +76,7 @@ public class DoActionTag extends Tag implements ASMSource { * * @param version SWF version * @param actions + * @param writer * @return ASM source * @throws java.lang.InterruptedException */ diff --git a/trunk/src/com/jpexs/decompiler/flash/tags/DoInitActionTag.java b/trunk/src/com/jpexs/decompiler/flash/tags/DoInitActionTag.java index d2eae2750..1cf1a4609 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/DoInitActionTag.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/DoInitActionTag.java @@ -106,6 +106,7 @@ public class DoInitActionTag extends CharacterIdTag implements ASMSource { * * @param version SWF version * @param actions + * @param writer * @return ASM source * @throws java.lang.InterruptedException */ diff --git a/trunk/src/com/jpexs/decompiler/flash/tags/base/ASMSource.java b/trunk/src/com/jpexs/decompiler/flash/tags/base/ASMSource.java index abadbc801..e7ef64f22 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/base/ASMSource.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/base/ASMSource.java @@ -35,6 +35,7 @@ public interface ASMSource extends TreeItem { * * @param version SWF version * @param exportMode PCode or hex? + * @param writer * @param actions * @return ASM source * @throws java.lang.InterruptedException diff --git a/trunk/src/com/jpexs/decompiler/flash/types/BUTTONCONDACTION.java b/trunk/src/com/jpexs/decompiler/flash/types/BUTTONCONDACTION.java index dbf147f66..63dd85a3c 100644 --- a/trunk/src/com/jpexs/decompiler/flash/types/BUTTONCONDACTION.java +++ b/trunk/src/com/jpexs/decompiler/flash/types/BUTTONCONDACTION.java @@ -160,6 +160,7 @@ public class BUTTONCONDACTION implements ASMSource, Exportable, ContainerItem { * * @param version SWF version * @param actions + * @param writer * @return ASM source * @throws java.lang.InterruptedException */ diff --git a/trunk/src/com/jpexs/decompiler/flash/types/CLIPACTIONRECORD.java b/trunk/src/com/jpexs/decompiler/flash/types/CLIPACTIONRECORD.java index 204e2c8a2..6f3c21b0c 100644 --- a/trunk/src/com/jpexs/decompiler/flash/types/CLIPACTIONRECORD.java +++ b/trunk/src/com/jpexs/decompiler/flash/types/CLIPACTIONRECORD.java @@ -166,6 +166,7 @@ public class CLIPACTIONRECORD implements ASMSource, Exportable, ContainerItem { * * @param version SWF version * @param actions + * @param writer * @return ASM source * @throws java.lang.InterruptedException */ diff --git a/trunk/src/com/jpexs/decompiler/flash/types/CXFORM.java b/trunk/src/com/jpexs/decompiler/flash/types/CXFORM.java index 880588358..9ebab78c8 100644 --- a/trunk/src/com/jpexs/decompiler/flash/types/CXFORM.java +++ b/trunk/src/com/jpexs/decompiler/flash/types/CXFORM.java @@ -16,6 +16,7 @@ */ package com.jpexs.decompiler.flash.types; +import com.jpexs.decompiler.flash.types.annotations.Calculated; import com.jpexs.decompiler.flash.types.annotations.SWFType; import com.jpexs.decompiler.flash.types.filters.Filtering; import com.jpexs.helpers.SerializableImage; @@ -36,6 +37,7 @@ public class CXFORM { * Has color multiply values */ public boolean hasMultTerms; + @Calculated @SWFType(value = BasicType.UB, count = 4) public int nbits; /** diff --git a/trunk/src/com/jpexs/decompiler/flash/types/CXFORMWITHALPHA.java b/trunk/src/com/jpexs/decompiler/flash/types/CXFORMWITHALPHA.java index bde4d0da4..2fb82459b 100644 --- a/trunk/src/com/jpexs/decompiler/flash/types/CXFORMWITHALPHA.java +++ b/trunk/src/com/jpexs/decompiler/flash/types/CXFORMWITHALPHA.java @@ -16,6 +16,7 @@ */ package com.jpexs.decompiler.flash.types; +import com.jpexs.decompiler.flash.types.annotations.Calculated; import com.jpexs.decompiler.flash.types.annotations.Conditional; import com.jpexs.decompiler.flash.types.annotations.SWFType; import com.jpexs.decompiler.flash.types.filters.Filtering; @@ -86,6 +87,7 @@ public class CXFORMWITHALPHA { @SWFType(value = BasicType.SB, countField = "nbits") public int alphaAddTerm; + @Calculated @SWFType(value = BasicType.UB, count = 4) public int nbits; diff --git a/trunk/src/com/jpexs/decompiler/flash/types/MATRIX.java b/trunk/src/com/jpexs/decompiler/flash/types/MATRIX.java index 216f6d5e2..36c6b6b81 100644 --- a/trunk/src/com/jpexs/decompiler/flash/types/MATRIX.java +++ b/trunk/src/com/jpexs/decompiler/flash/types/MATRIX.java @@ -16,6 +16,7 @@ */ package com.jpexs.decompiler.flash.types; +import com.jpexs.decompiler.flash.types.annotations.Calculated; import com.jpexs.decompiler.flash.types.annotations.Conditional; import com.jpexs.decompiler.flash.types.annotations.SWFType; import java.awt.Point; @@ -72,12 +73,15 @@ public class MATRIX implements Serializable { @SWFType(value = BasicType.SB, countField = "nTranslateBits") public int translateY; + @Calculated @SWFType(value = BasicType.UB, count = 5) public int nTranslateBits; + @Calculated @SWFType(value = BasicType.UB, count = 5) public int nRotateBits; + @Calculated @SWFType(value = BasicType.UB, count = 5) public int nScaleBits; diff --git a/trunk/src/com/jpexs/decompiler/flash/types/RECT.java b/trunk/src/com/jpexs/decompiler/flash/types/RECT.java index 77471c319..ed1bf8b77 100644 --- a/trunk/src/com/jpexs/decompiler/flash/types/RECT.java +++ b/trunk/src/com/jpexs/decompiler/flash/types/RECT.java @@ -16,6 +16,7 @@ */ package com.jpexs.decompiler.flash.types; +import com.jpexs.decompiler.flash.types.annotations.Calculated; import com.jpexs.decompiler.flash.types.annotations.SWFType; import java.awt.Point; import java.io.Serializable; @@ -51,6 +52,7 @@ public class RECT implements Serializable { @SWFType(value = BasicType.SB, countField = "nbits") public int Ymax; + @Calculated @SWFType(value = BasicType.UB, count = 5) public int nbits; diff --git a/trunk/src/com/jpexs/decompiler/flash/types/annotations/Calculated.java b/trunk/src/com/jpexs/decompiler/flash/types/annotations/Calculated.java new file mode 100644 index 000000000..4f4e3be94 --- /dev/null +++ b/trunk/src/com/jpexs/decompiler/flash/types/annotations/Calculated.java @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2014 JPEXS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.jpexs.decompiler.flash.types.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Field is internal + * + * @author JPEXS + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.FIELD) +public @interface Calculated { + +} diff --git a/trunk/src/com/jpexs/decompiler/flash/types/shaperecords/CurvedEdgeRecord.java b/trunk/src/com/jpexs/decompiler/flash/types/shaperecords/CurvedEdgeRecord.java index 92ba37b41..1fa14921a 100644 --- a/trunk/src/com/jpexs/decompiler/flash/types/shaperecords/CurvedEdgeRecord.java +++ b/trunk/src/com/jpexs/decompiler/flash/types/shaperecords/CurvedEdgeRecord.java @@ -18,6 +18,7 @@ package com.jpexs.decompiler.flash.types.shaperecords; import com.jpexs.decompiler.flash.SWFOutputStream; import com.jpexs.decompiler.flash.types.BasicType; +import com.jpexs.decompiler.flash.types.annotations.Calculated; import com.jpexs.decompiler.flash.types.annotations.SWFType; /** @@ -29,6 +30,7 @@ public class CurvedEdgeRecord extends SHAPERECORD { public boolean typeFlag = true; public boolean straightFlag = false; + @Calculated @SWFType(value = BasicType.UB, count = 4) public int numBits; diff --git a/trunk/src/com/jpexs/decompiler/flash/types/shaperecords/StraightEdgeRecord.java b/trunk/src/com/jpexs/decompiler/flash/types/shaperecords/StraightEdgeRecord.java index 8f9265bbc..5472c25af 100644 --- a/trunk/src/com/jpexs/decompiler/flash/types/shaperecords/StraightEdgeRecord.java +++ b/trunk/src/com/jpexs/decompiler/flash/types/shaperecords/StraightEdgeRecord.java @@ -18,6 +18,7 @@ package com.jpexs.decompiler.flash.types.shaperecords; import com.jpexs.decompiler.flash.SWFOutputStream; import com.jpexs.decompiler.flash.types.BasicType; +import com.jpexs.decompiler.flash.types.annotations.Calculated; import com.jpexs.decompiler.flash.types.annotations.Conditional; import com.jpexs.decompiler.flash.types.annotations.SWFType; @@ -40,6 +41,8 @@ public class StraightEdgeRecord extends SHAPERECORD { */ public int typeFlag = 1; public int straightFlag = 1; + + @Calculated @SWFType(value = BasicType.UB, count = 4) public int numBits; public boolean generalLineFlag; diff --git a/trunk/src/com/jpexs/decompiler/flash/types/shaperecords/StyleChangeRecord.java b/trunk/src/com/jpexs/decompiler/flash/types/shaperecords/StyleChangeRecord.java index 688b37b93..eddd28c90 100644 --- a/trunk/src/com/jpexs/decompiler/flash/types/shaperecords/StyleChangeRecord.java +++ b/trunk/src/com/jpexs/decompiler/flash/types/shaperecords/StyleChangeRecord.java @@ -20,6 +20,7 @@ import com.jpexs.decompiler.flash.SWFOutputStream; import com.jpexs.decompiler.flash.types.BasicType; import com.jpexs.decompiler.flash.types.FILLSTYLEARRAY; import com.jpexs.decompiler.flash.types.LINESTYLEARRAY; +import com.jpexs.decompiler.flash.types.annotations.Calculated; import com.jpexs.decompiler.flash.types.annotations.Conditional; import com.jpexs.decompiler.flash.types.annotations.SWFType; import java.util.Set; @@ -39,6 +40,7 @@ public class StyleChangeRecord extends SHAPERECORD implements Cloneable { public boolean stateFillStyle0; public boolean stateMoveTo; + @Calculated @SWFType(value = BasicType.UB, count = 5) @Conditional("stateMoveTo") public int moveBits; @@ -69,9 +71,11 @@ public class StyleChangeRecord extends SHAPERECORD implements Cloneable { @Conditional("stateNewStyles") public LINESTYLEARRAY lineStyles; + @Calculated @Conditional("stateNewStyles") public int numFillBits; + @Calculated @Conditional("stateNewStyles") public int numLineBits; diff --git a/trunk/src/com/sun/jna/platform/win32/WinNT.java b/trunk/src/com/sun/jna/platform/win32/WinNT.java index 2085895cd..8822f607b 100644 --- a/trunk/src/com/sun/jna/platform/win32/WinNT.java +++ b/trunk/src/com/sun/jna/platform/win32/WinNT.java @@ -787,6 +787,7 @@ public interface WinNT extends WinError, WinDef, WinBase, BaseTSD { /** * Override to the appropriate object for INVALID_HANDLE_VALUE. + * @param nativeValue * @param context * @return */ diff --git a/trunk/src/com/sun/jna/platform/win32/WinUser.java b/trunk/src/com/sun/jna/platform/win32/WinUser.java index 2aad0ee3a..20505b31e 100644 --- a/trunk/src/com/sun/jna/platform/win32/WinUser.java +++ b/trunk/src/com/sun/jna/platform/win32/WinUser.java @@ -195,6 +195,7 @@ public interface WinUser extends StdCallLibrary, WinDef { /** * Return whether to continue enumeration. + * @param hWnd * @param data * @return */