From 66261ff16c63ec62903087366d34c1388bfc2e19 Mon Sep 17 00:00:00 2001 From: Brian Reynolds Date: Thu, 23 Mar 2023 19:02:44 -0400 Subject: [PATCH 1/3] Change Property Buttons now have a description field, which is displayed in the editor if filled in --- .../properties/ChangePropertyButton.java | 51 ++++++++++++------- .../java/VASSAL/configure/ConfigureTree.java | 9 ++++ 2 files changed, 41 insertions(+), 19 deletions(-) diff --git a/vassal-app/src/main/java/VASSAL/build/module/properties/ChangePropertyButton.java b/vassal-app/src/main/java/VASSAL/build/module/properties/ChangePropertyButton.java index 9e4ca9aeb7..63900d33b2 100644 --- a/vassal-app/src/main/java/VASSAL/build/module/properties/ChangePropertyButton.java +++ b/vassal-app/src/main/java/VASSAL/build/module/properties/ChangePropertyButton.java @@ -33,13 +33,12 @@ import VASSAL.script.expression.Expression; import VASSAL.tools.FormattedString; import VASSAL.tools.LaunchButton; +import org.apache.commons.lang3.ArrayUtils; import java.awt.Component; import java.util.ArrayList; import java.util.List; -import org.apache.commons.lang3.ArrayUtils; - /** * Adds a toolbar button that changes the value of a global property * @@ -51,6 +50,7 @@ public class ChangePropertyButton extends AbstractToolbarItem implements Propert public static final String BUTTON_TOOLTIP = "tooltip"; //NON-NLS public static final String BUTTON_ICON = "icon"; //NON-NLS public static final String HOTKEY = "hotkey"; //NON-NLS + public static final String DESCRIPTION = "desc"; //NON-NLS public static final String PROPERTY_CHANGER = "propChanger"; //NON-NLS @@ -67,6 +67,7 @@ public class ChangePropertyButton extends AbstractToolbarItem implements Propert protected GlobalProperty property; protected PropertyChangerConfigurer propChangeConfig = new PropertyChangerConfigurer(null, null, this); protected FormattedString format = new FormattedString(); + protected String desc = ""; public ChangePropertyButton() { setNameKey(""); @@ -111,29 +112,35 @@ public PropertyChanger getPropertyChanger() { @Override public String[] getAttributeDescriptions() { - return ArrayUtils.addAll( - super.getAttributeDescriptions(), - Resources.getString("Editor.report_format"), - Resources.getString("Editor.ChangePropertyButton.options") - ); + String[] descs = { Resources.getString("Editor.description_label") }; + for (final String s : super.getAttributeDescriptions()) { + descs = ArrayUtils.add(descs, s); + } + descs = ArrayUtils.add(descs, Resources.getString("Editor.report_format")); + descs = ArrayUtils.add(descs, Resources.getString("Editor.ChangePropertyButton.options")); + return descs; } @Override public Class[] getAttributeTypes() { - return ArrayUtils.addAll( - super.getAttributeTypes(), - ReportFormatConfig.class, - PropChangerOptions.class - ); + Class[] types = { String.class }; + for (final Class c : super.getAttributeTypes()) { + types = ArrayUtils.add(types, c); + } + types = ArrayUtils.add(types, ReportFormatConfig.class); + types = ArrayUtils.add(types, PropChangerOptions.class); + return types; } @Override public String[] getAttributeNames() { - return ArrayUtils.addAll( - super.getAttributeNames(), - REPORT_FORMAT, - PROPERTY_CHANGER - ); + String[] names = { DESCRIPTION }; + for (final String s : super.getAttributeNames()) { + names = ArrayUtils.add(names, s); + } + names = ArrayUtils.add(names, REPORT_FORMAT); + names = ArrayUtils.add(names, PROPERTY_CHANGER); + return names; } @Override @@ -157,7 +164,10 @@ public Configurer getConfigurer(AutoConfigurable c, String key, String name) { @Override public void setAttribute(String key, Object value) { - if (PROPERTY_CHANGER.equals(key)) { + if (DESCRIPTION.equals(key)) { + desc = (String) value; + } + else if (PROPERTY_CHANGER.equals(key)) { if (value instanceof String) { propChangeConfig.setValue((String)value); } @@ -178,7 +188,10 @@ else if (REPORT_FORMAT.equals(key)) { @Override public String getAttributeValueString(String key) { - if (PROPERTY_CHANGER.equals(key)) { + if (DESCRIPTION.equals(key)) { + return desc; + } + else if (PROPERTY_CHANGER.equals(key)) { return propChangeConfig.getValueString(); } else if (REPORT_FORMAT.equals(key)) { diff --git a/vassal-app/src/main/java/VASSAL/configure/ConfigureTree.java b/vassal-app/src/main/java/VASSAL/configure/ConfigureTree.java index 59d56744e7..a3c5e2bde5 100644 --- a/vassal-app/src/main/java/VASSAL/configure/ConfigureTree.java +++ b/vassal-app/src/main/java/VASSAL/configure/ConfigureTree.java @@ -41,6 +41,7 @@ import VASSAL.build.module.map.MassKeyCommand; import VASSAL.build.module.map.SetupStack; import VASSAL.build.module.map.boardPicker.board.mapgrid.Zone; +import VASSAL.build.module.properties.ChangePropertyButton; import VASSAL.build.module.properties.GlobalProperties; import VASSAL.build.module.properties.GlobalProperty; import VASSAL.build.module.properties.GlobalTranslatableMessage; @@ -2654,6 +2655,14 @@ public String toString() { } } } + + if (c instanceof ChangePropertyButton) { + final ChangePropertyButton cpb = (ChangePropertyButton)c; + final String desc = cpb.getAttributeValueString(ChangePropertyButton.DESCRIPTION); + if ((desc != null) && !desc.isEmpty()) { + description += " - " + desc; + } + } } return description; } From 20fa3db24170aeefbe6ea7134767ca7516bd5b8d Mon Sep 17 00:00:00 2001 From: Brian Reynolds Date: Wed, 29 Mar 2023 15:01:19 -0400 Subject: [PATCH 2/3] more efficient? --- .../module/properties/ChangePropertyButton.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/vassal-app/src/main/java/VASSAL/build/module/properties/ChangePropertyButton.java b/vassal-app/src/main/java/VASSAL/build/module/properties/ChangePropertyButton.java index 63900d33b2..4bc22960e0 100644 --- a/vassal-app/src/main/java/VASSAL/build/module/properties/ChangePropertyButton.java +++ b/vassal-app/src/main/java/VASSAL/build/module/properties/ChangePropertyButton.java @@ -37,7 +37,9 @@ import java.awt.Component; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; +import java.util.stream.Stream; /** * Adds a toolbar button that changes the value of a global property @@ -112,13 +114,12 @@ public PropertyChanger getPropertyChanger() { @Override public String[] getAttributeDescriptions() { - String[] descs = { Resources.getString("Editor.description_label") }; - for (final String s : super.getAttributeDescriptions()) { - descs = ArrayUtils.add(descs, s); - } - descs = ArrayUtils.add(descs, Resources.getString("Editor.report_format")); - descs = ArrayUtils.add(descs, Resources.getString("Editor.ChangePropertyButton.options")); - return descs; + final Stream.Builder b = Stream.builder().add(Resources.getString("Editor.description_label")); + Arrays.stream(super.getAttributeDescriptions()).forEach(b::add); + b.add(Resources.getString("Editor.report_format")) + .add(Resources.getString("Editor.ChangePropertyButton.options")); + + return b.build().toArray(String[]::new); } @Override From 873d447c5b5429a2c45017e3061f3c89ce7e15f6 Mon Sep 17 00:00:00 2001 From: Brian Reynolds Date: Wed, 29 Mar 2023 17:46:22 -0400 Subject: [PATCH 3/3] further cleanup --- .../properties/ChangePropertyButton.java | 24 +++++++------------ 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/vassal-app/src/main/java/VASSAL/build/module/properties/ChangePropertyButton.java b/vassal-app/src/main/java/VASSAL/build/module/properties/ChangePropertyButton.java index 4bc22960e0..a21855a952 100644 --- a/vassal-app/src/main/java/VASSAL/build/module/properties/ChangePropertyButton.java +++ b/vassal-app/src/main/java/VASSAL/build/module/properties/ChangePropertyButton.java @@ -33,7 +33,6 @@ import VASSAL.script.expression.Expression; import VASSAL.tools.FormattedString; import VASSAL.tools.LaunchButton; -import org.apache.commons.lang3.ArrayUtils; import java.awt.Component; import java.util.ArrayList; @@ -118,30 +117,23 @@ public String[] getAttributeDescriptions() { Arrays.stream(super.getAttributeDescriptions()).forEach(b::add); b.add(Resources.getString("Editor.report_format")) .add(Resources.getString("Editor.ChangePropertyButton.options")); - return b.build().toArray(String[]::new); } @Override public Class[] getAttributeTypes() { - Class[] types = { String.class }; - for (final Class c : super.getAttributeTypes()) { - types = ArrayUtils.add(types, c); - } - types = ArrayUtils.add(types, ReportFormatConfig.class); - types = ArrayUtils.add(types, PropChangerOptions.class); - return types; + final Stream.Builder b = Stream.builder().add(String.class); + Arrays.stream(super.getAttributeTypes()).forEach(b::add); + b.add(ReportFormatConfig.class).add(PropChangerOptions.class); + return b.build().toArray(Class[]::new); } @Override public String[] getAttributeNames() { - String[] names = { DESCRIPTION }; - for (final String s : super.getAttributeNames()) { - names = ArrayUtils.add(names, s); - } - names = ArrayUtils.add(names, REPORT_FORMAT); - names = ArrayUtils.add(names, PROPERTY_CHANGER); - return names; + final Stream.Builder b = Stream.builder().add(DESCRIPTION); + Arrays.stream(super.getAttributeNames()).forEach(b::add); + b.add(REPORT_FORMAT).add(PROPERTY_CHANGER); + return b.build().toArray(String[]::new); } @Override