Skip to content

Commit

Permalink
Merge pull request #12136 from Cattlesquat/ChangeToolbarDesc
Browse files Browse the repository at this point in the history
12136 - Change Property Buttons now have a description field, which is displayed in the editor if filled in
  • Loading branch information
uckelman authored Mar 29, 2023
2 parents 09aff76 + 873d447 commit d891a12
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@

import java.awt.Component;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.apache.commons.lang3.ArrayUtils;
import java.util.stream.Stream;

/**
* Adds a toolbar button that changes the value of a global property
Expand All @@ -51,6 +51,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

Expand All @@ -67,6 +68,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("");
Expand Down Expand Up @@ -111,29 +113,27 @@ public PropertyChanger getPropertyChanger() {

@Override
public String[] getAttributeDescriptions() {
return ArrayUtils.addAll(
super.getAttributeDescriptions(),
Resources.getString("Editor.report_format"),
Resources.getString("Editor.ChangePropertyButton.options")
);
final Stream.Builder<Object> 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
public Class<?>[] getAttributeTypes() {
return ArrayUtils.addAll(
super.getAttributeTypes(),
ReportFormatConfig.class,
PropChangerOptions.class
);
final Stream.Builder<Object> 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() {
return ArrayUtils.addAll(
super.getAttributeNames(),
REPORT_FORMAT,
PROPERTY_CHANGER
);
final Stream.Builder<Object> 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
Expand All @@ -157,7 +157,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);
}
Expand All @@ -178,7 +181,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)) {
Expand Down
9 changes: 9 additions & 0 deletions vassal-app/src/main/java/VASSAL/configure/ConfigureTree.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit d891a12

Please sign in to comment.