From 6a6a2667761fd2d4fe431c01c9a713a2f72527c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=C5=99=C3=ADk?= Date: Sat, 23 Jan 2016 20:10:18 +0100 Subject: [PATCH] Better tree labels in generic tag editor (Raw edit) --- .../flash/types/FILLSTYLEARRAY.java | 2 + .../decompiler/flash/types/GRADIENT.java | 2 + .../flash/types/LINESTYLEARRAY.java | 2 + .../jpexs/decompiler/flash/types/SHAPE.java | 2 + .../flash/gui/GenericTagTreePanel.java | 131 ++++++++++-------- 5 files changed, 81 insertions(+), 58 deletions(-) diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/FILLSTYLEARRAY.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/FILLSTYLEARRAY.java index 0f5972225..6da85ad10 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/FILLSTYLEARRAY.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/FILLSTYLEARRAY.java @@ -17,6 +17,7 @@ package com.jpexs.decompiler.flash.types; import com.jpexs.decompiler.flash.tags.base.NeedsCharacters; +import com.jpexs.decompiler.flash.types.annotations.SWFArray; import java.io.Serializable; import java.util.Set; @@ -26,6 +27,7 @@ import java.util.Set; */ public class FILLSTYLEARRAY implements NeedsCharacters, Serializable { + @SWFArray(value = "fillStyle") public FILLSTYLE[] fillStyles; @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/GRADIENT.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/GRADIENT.java index e220f7a38..e336cbdce 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/GRADIENT.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/GRADIENT.java @@ -16,6 +16,7 @@ */ package com.jpexs.decompiler.flash.types; +import com.jpexs.decompiler.flash.types.annotations.SWFArray; import com.jpexs.decompiler.flash.types.annotations.SWFType; import java.io.Serializable; @@ -53,5 +54,6 @@ public class GRADIENT implements Serializable { public static final int INTERPOLATION_RESERVED2 = 3; + @SWFArray(value = "record") public GRADRECORD[] gradientRecords = new GRADRECORD[0]; } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/LINESTYLEARRAY.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/LINESTYLEARRAY.java index 18b076be8..f3922c2b2 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/LINESTYLEARRAY.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/LINESTYLEARRAY.java @@ -17,6 +17,7 @@ package com.jpexs.decompiler.flash.types; import com.jpexs.decompiler.flash.tags.base.NeedsCharacters; +import com.jpexs.decompiler.flash.types.annotations.SWFArray; import java.io.Serializable; import java.util.Set; @@ -26,6 +27,7 @@ import java.util.Set; */ public class LINESTYLEARRAY implements NeedsCharacters, Serializable { + @SWFArray(value = "lineStyle") public LINESTYLE[] lineStyles = new LINESTYLE[0]; @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/SHAPE.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/SHAPE.java index a8a5ffde2..fa45695ef 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/SHAPE.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/SHAPE.java @@ -19,6 +19,7 @@ package com.jpexs.decompiler.flash.types; import com.jpexs.decompiler.flash.SWF; import com.jpexs.decompiler.flash.exporters.shape.PathExporter; import com.jpexs.decompiler.flash.tags.base.NeedsCharacters; +import com.jpexs.decompiler.flash.types.annotations.SWFArray; import com.jpexs.decompiler.flash.types.annotations.SWFType; import com.jpexs.decompiler.flash.types.shaperecords.EndShapeRecord; import com.jpexs.decompiler.flash.types.shaperecords.SHAPERECORD; @@ -42,6 +43,7 @@ public class SHAPE implements NeedsCharacters, Serializable { @SWFType(value = BasicType.UB, count = 4) public int numLineBits; + @SWFArray(value = "record") public List shapeRecords; private Shape cachedOutline; diff --git a/src/com/jpexs/decompiler/flash/gui/GenericTagTreePanel.java b/src/com/jpexs/decompiler/flash/gui/GenericTagTreePanel.java index 7411c54bc..6f27fc481 100644 --- a/src/com/jpexs/decompiler/flash/gui/GenericTagTreePanel.java +++ b/src/com/jpexs/decompiler/flash/gui/GenericTagTreePanel.java @@ -553,15 +553,66 @@ public class GenericTagTreePanel extends GenericTagPanel { public String getType(int fieldIndex) { SWFType swfType = fieldSet.get(fieldIndex).getAnnotation(SWFType.class); SWFArray swfArray = fieldSet.get(fieldIndex).getAnnotation(SWFArray.class); - String typeStr = null; - if ((swfType != null || swfArray != null) && !(ReflectionTools.needsIndex(fieldSet.get(fieldIndex)) && (index > -1))) { - Class type = fieldSet.get(fieldIndex).getType(); - if (ReflectionTools.needsIndex(fieldSet.get(fieldIndex))) { - type = ReflectionTools.getFieldSubType(obj, fieldSet.get(fieldIndex)); - } - typeStr = swfTypeToString(type, swfType, swfArray); + Class declaredType = fieldSet.get(fieldIndex).getType(); + boolean isArray = ReflectionTools.needsIndex(fieldSet.get(fieldIndex)) || swfArray != null; + boolean isArrayParent = isArray && index == -1; + + Class declaredSubType = isArray ? ReflectionTools.getFieldSubType(obj, fieldSet.get(fieldIndex)) : null; + + Class type = declaredType; + if (declaredSubType != null) { + type = declaredSubType; } + + if (isArray && !isArrayParent) { + //get real value object type + try { + Object val = ReflectionTools.getValue(obj, fieldSet.get(fieldIndex), index); + if (val != null) { + type = val.getClass(); + } + } catch (IllegalArgumentException | IllegalAccessException ex) { + //ignore + } + } + + String typeStr = type.getSimpleName(); + + if (swfType != null && swfType.value() != BasicType.OTHER) { + typeStr = "" + swfType.value(); + if (swfType.count() > 0) { + typeStr += "[" + swfType.count(); + if (swfType.countAdd() > 0) { + typeStr += " + " + swfType.countAdd(); + } + typeStr += "]"; + } else if (!swfType.countField().isEmpty()) { + typeStr += "[" + swfType.countField(); + if (swfType.countAdd() > 0) { + typeStr += " + " + swfType.countAdd(); + } + typeStr += "]"; + } + } + + String arrayBrackets = ""; + if (isArrayParent) { + if (swfArray != null) { + if (swfArray.count() > 0) { + arrayBrackets = "[" + swfArray.count() + "]"; + } else if (!swfArray.countField().isEmpty()) { + arrayBrackets = "[" + swfArray.countField() + "]"; + } else { + arrayBrackets = "[]"; + } + } else { + arrayBrackets = "[]"; + } + } + typeStr += arrayBrackets; + return typeStr; + } public String getNameType(int fieldIndex) { @@ -570,26 +621,25 @@ public class GenericTagTreePanel extends GenericTagPanel { } public String getName(int fieldIndex) { + SWFArray swfArray = fieldSet.get(fieldIndex).getAnnotation(SWFArray.class); + + boolean isArray = ReflectionTools.needsIndex(fieldSet.get(fieldIndex)) || swfArray != null; + boolean isArrayParent = isArray && index == -1; + String name = ""; - if (swfArray != null) { + + if (!isArray || isArrayParent) { + name = fieldSet.get(fieldIndex).getName(); + } else if (swfArray != null && !isArrayParent) { name = swfArray.value(); } - Object val = null; - try { - if (index > -1) { - val = ReflectionTools.getValue(obj, fieldSet.get(fieldIndex), index); - } - } catch (IllegalArgumentException | IllegalAccessException ex) { - //ignore - } - String typeAdd = ""; - if (val != null) { - typeAdd = " : " + val.getClass().getSimpleName(); + if (!isArrayParent && isArray) { + name += "[" + index + "]"; } - return (index > -1 ? name + "[" + index + "]" + typeAdd : fieldSet.get(fieldIndex).getName()); + return name; } public Object getValue(int fieldIndex) { @@ -861,44 +911,9 @@ public class GenericTagTreePanel extends GenericTagPanel { return tag; } - public static String swfArrayToString(SWFArray swfArray) { - String result = ""; - if (swfArray == null) { - return result; - } - if (swfArray.count() > 0) { - result += "[" + swfArray.count() + "]"; - } else if (!swfArray.countField().isEmpty()) { - result += "[" + swfArray.countField() + "]"; - } - return result; - } - - public static String swfTypeToString(Class type, SWFType swfType, SWFArray swfArray) { - String stype = type.getSimpleName(); - if (swfType == null) { - return stype + swfArrayToString(swfArray); - } - String result = swfType.value().toString(); - if (swfType.value() == BasicType.OTHER) { - result = stype; - } - if (swfType.count() > 0) { - result += "[" + swfType.count(); - if (swfType.countAdd() > 0) { - result += " + " + swfType.countAdd(); - } - result += "]"; - } else if (!swfType.countField().isEmpty()) { - result += "[" + swfType.countField(); - if (swfType.countAdd() > 0) { - result += " + " + swfType.countAdd(); - } - result += "]"; - } - return result + swfArrayToString(swfArray); - } - + /*public static String swfTypeToString(Class type, SWFType swfType, SWFArray swfArray, boolean arrayHeader) { + S + }*/ private static boolean hasEditor(Object obj, Field field, int index) { boolean isByteArray = field.getType().equals(byte[].class); if (!isByteArray && ReflectionTools.needsIndex(field) && index == -1) {