From 4e28ed3839ab604eb84732bc53df2d0c04e0452a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=C5=99=C3=ADk?= Date: Sat, 14 Oct 2023 22:20:20 +0200 Subject: [PATCH] Fixed Generic tag editor - GRADIENT filters fields Disallow manually adding items to convolution matrix --- CHANGELOG.md | 1 + .../flash/types/annotations/SWFType.java | 2 + .../types/filters/CONVOLUTIONFILTER.java | 2 +- .../flash/gui/GenericTagTreePanel.java | 60 ++++++++++++++++--- 4 files changed, 56 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5d709b013..da2a194bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,6 +43,7 @@ All notable changes to this project will be documented in this file. - Box blur display rounding errors - Generic tag editor - display of color values in arrays (filters, etc.) - Generic tag editor - display of array brackets +- Generic tag editor - GRADIENT filters fields ## [19.0.0] - 2023-10-01 ### Added diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/annotations/SWFType.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/annotations/SWFType.java index 3c830834d..e198e5693 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/annotations/SWFType.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/annotations/SWFType.java @@ -48,4 +48,6 @@ public @interface SWFType { //Count to add to countField int countAdd() default 0; + + boolean canAdd() default true; } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/filters/CONVOLUTIONFILTER.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/filters/CONVOLUTIONFILTER.java index 6d83ab0f3..37d26e11a 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/filters/CONVOLUTIONFILTER.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/filters/CONVOLUTIONFILTER.java @@ -62,7 +62,7 @@ public class CONVOLUTIONFILTER extends FILTER { /** * Matrix values */ - @SWFType(BasicType.FLOAT) + @SWFType(value = BasicType.FLOAT, countField = "matrixX * matrixY", canAdd = false) public float[] matrix = new float[] { 0, 0, 0, 0, 1, 0, diff --git a/src/com/jpexs/decompiler/flash/gui/GenericTagTreePanel.java b/src/com/jpexs/decompiler/flash/gui/GenericTagTreePanel.java index 96fb2e770..53bf21219 100644 --- a/src/com/jpexs/decompiler/flash/gui/GenericTagTreePanel.java +++ b/src/com/jpexs/decompiler/flash/gui/GenericTagTreePanel.java @@ -269,6 +269,11 @@ public class GenericTagTreePanel extends GenericTagPanel { public Class annotationType() { return SWFType.class; } + + @Override + public boolean canAdd() { + return swfType.canAdd(); + } }; } catch (AnnotationParseException | IllegalArgumentException | IllegalAccessException ex) { logger.log(Level.SEVERE, null, ex); @@ -527,6 +532,7 @@ public class GenericTagTreePanel extends GenericTagPanel { Field field = fnode.fieldSet.get(FIELD_INDEX); if (ReflectionTools.needsIndex(field)) { SWFArray swfArray = fnode.fieldSet.get(FIELD_INDEX).getAnnotation(SWFArray.class); + SWFType swfType = fnode.fieldSet.get(FIELD_INDEX).getAnnotation(SWFType.class); String itemStr = ""; if (swfArray != null) { @@ -548,6 +554,11 @@ public class GenericTagTreePanel extends GenericTagPanel { canAdd = false; } } + if (swfType != null) { + if (!swfType.canAdd()) { + canAdd = false; + } + } JPopupMenu p = new JPopupMenu(); JMenuItem mi; @@ -1505,19 +1516,35 @@ public class GenericTagTreePanel extends GenericTagPanel { private void addItem(Object obj, Field field, int index, Class cls) { SWFArray swfArray = field.getAnnotation(SWFArray.class); - if (swfArray != null && !swfArray.countField().isEmpty()) { //Fields with same countField must be enlarged too + SWFType swfType = field.getAnnotation(SWFType.class); + String countFieldName = null; + if (swfArray != null && !swfArray.countField().isEmpty()) { + countFieldName = swfArray.countField(); + } + if (swfType != null && !swfType.countField().isEmpty()) { + countFieldName = swfType.countField(); + } + + if (countFieldName != null) { //Fields with same countField must be enlarged too Field[] fields = obj.getClass().getDeclaredFields(); List sameFlds = new ArrayList<>(); for (int f = 0; f < fields.length; f++) { SWFArray fieldSwfArray = fields[f].getAnnotation(SWFArray.class); - if (fieldSwfArray != null && fieldSwfArray.countField().equals(swfArray.countField())) { + SWFType fieldSwfType = fields[f].getAnnotation(SWFType.class); + String fieldCountFieldName = null; + if (fieldSwfArray != null && !fieldSwfArray.countField().isEmpty()) { + fieldCountFieldName = fieldSwfArray.countField(); + } + if (fieldSwfType != null && !fieldSwfType.countField().isEmpty()) { + fieldCountFieldName = fieldSwfType.countField(); + } + if (fieldCountFieldName != null && fieldCountFieldName.equals(countFieldName)) { sameFlds.add(f); if (cls == null && !ReflectionTools.canAddToField(obj, fields[f])) { JOptionPane.showMessageDialog(this, "This field is abstract, cannot be instantiated, sorry."); //TODO!!! return; } - - } + } } for (int f : sameFlds) { ReflectionTools.addToField(obj, fields[f], index, true, cls); @@ -1536,7 +1563,7 @@ public class GenericTagTreePanel extends GenericTagPanel { } try { //If countField exists, increment, otherwise do nothing - Field countField = obj.getClass().getDeclaredField(swfArray.countField()); + Field countField = obj.getClass().getDeclaredField(countFieldName); int cnt = countField.getInt(obj); cnt++; countField.setInt(obj, cnt); @@ -1585,17 +1612,34 @@ public class GenericTagTreePanel extends GenericTagPanel { private void removeItem(Object obj, Field field, int index) { SWFArray swfArray = field.getAnnotation(SWFArray.class); - if (swfArray != null && !swfArray.countField().isEmpty()) { //Fields with same countField must be removed from too + SWFType swfType = field.getAnnotation(SWFType.class); + String countFieldName = null; + if (swfArray != null && !swfArray.countField().isEmpty()) { + countFieldName = swfArray.countField(); + } + if (swfType != null && !swfType.countField().isEmpty()) { + countFieldName = swfType.countField(); + } + if (countFieldName != null) { //Fields with same countField must be removed from too Field[] fields = obj.getClass().getDeclaredFields(); for (int f = 0; f < fields.length; f++) { SWFArray fieldSwfArray = fields[f].getAnnotation(SWFArray.class); - if (fieldSwfArray != null && fieldSwfArray.countField().equals(swfArray.countField())) { + SWFType fieldSwfType = fields[f].getAnnotation(SWFType.class); + String fieldCountFieldName = null; + if (fieldSwfArray != null && !fieldSwfArray.countField().isEmpty()) { + fieldCountFieldName = fieldSwfArray.countField(); + } + if (fieldSwfType != null && !fieldSwfType.countField().isEmpty()) { + fieldCountFieldName = fieldSwfType.countField(); + } + + if (fieldCountFieldName != null && fieldCountFieldName.equals(countFieldName)) { ReflectionTools.removeFromField(obj, fields[f], index); } } try { //If countField exists, decrement, otherwise do nothing - Field countField = obj.getClass().getDeclaredField(swfArray.countField()); + Field countField = obj.getClass().getDeclaredField(countFieldName); int cnt = countField.getInt(obj); cnt--; countField.setInt(obj, cnt);