From 06065cca0ca0d71ae0dd8701863cb26119941804 Mon Sep 17 00:00:00 2001 From: Pjiesco Date: Fri, 6 Oct 2023 15:29:22 +0200 Subject: [PATCH 1/6] Feat: Setting Tooltip --- .../touchportal/annotations/Setting.java | 13 +++++++++++++ .../processor/SettingProcessor.java | 13 +++++++++++++ .../processor/utils/SpecUtils.java | 19 +++++++++++++++++++ .../touchportal/helpers/SettingHelper.java | 7 +++++++ .../TouchPortalSampleJavaPlugin.java | 7 +++++-- 5 files changed, 57 insertions(+), 2 deletions(-) diff --git a/Annotations/src/main/java/com/christophecvb/touchportal/annotations/Setting.java b/Annotations/src/main/java/com/christophecvb/touchportal/annotations/Setting.java index eded71f..6d276dc 100644 --- a/Annotations/src/main/java/com/christophecvb/touchportal/annotations/Setting.java +++ b/Annotations/src/main/java/com/christophecvb/touchportal/annotations/Setting.java @@ -99,4 +99,17 @@ * @return boolean isReadOnly */ boolean isReadOnly() default false; + + /** + * Setting Tooltip + * + * @return {@link Tooltip} tooltip + */ + Tooltip tooltip() default @Tooltip(body = ""); + + @interface Tooltip { + String title() default ""; + String body(); + String docUrl() default ""; + } } diff --git a/AnnotationsProcessor/src/main/java/com/christophecvb/touchportal/annotations/processor/SettingProcessor.java b/AnnotationsProcessor/src/main/java/com/christophecvb/touchportal/annotations/processor/SettingProcessor.java index 589f1c3..1cbb81a 100644 --- a/AnnotationsProcessor/src/main/java/com/christophecvb/touchportal/annotations/processor/SettingProcessor.java +++ b/AnnotationsProcessor/src/main/java/com/christophecvb/touchportal/annotations/processor/SettingProcessor.java @@ -34,6 +34,17 @@ public static Pair process(TouchPortalPluginAnnota jsonSetting.addProperty(SettingHelper.TYPE, desiredTPType); jsonSetting.addProperty(SettingHelper.DEFAULT, setting.defaultValue()); jsonSetting.addProperty(SettingHelper.IS_READ_ONLY, setting.isReadOnly()); + + if (!setting.tooltip().body().isBlank()) { + JsonObject tooltip = new JsonObject(); + + tooltip.addProperty(SettingHelper.Tooltip.TITLE, setting.tooltip().title()); + tooltip.addProperty(SettingHelper.Tooltip.BODY, setting.tooltip().body()); + tooltip.addProperty(SettingHelper.Tooltip.DOC_URL, setting.tooltip().docUrl()); + + jsonSetting.add(SettingHelper.TOOLTIP, tooltip); + } + switch (desiredTPType) { case SettingHelper.TYPE_TEXT: if (setting.maxLength() > 0) { @@ -66,6 +77,8 @@ public static Pair process(TouchPortalPluginAnnota throw new GenericHelper.TPTypeException.Builder(className).typeUnsupported(desiredTPType).forAnnotation(GenericHelper.TPTypeException.ForAnnotation.SETTING).build(); } + + return Pair.create(jsonSetting, settingTypeSpecBuilder); } } diff --git a/AnnotationsProcessor/src/main/java/com/christophecvb/touchportal/annotations/processor/utils/SpecUtils.java b/AnnotationsProcessor/src/main/java/com/christophecvb/touchportal/annotations/processor/utils/SpecUtils.java index c681c16..5f3ef7e 100644 --- a/AnnotationsProcessor/src/main/java/com/christophecvb/touchportal/annotations/processor/utils/SpecUtils.java +++ b/AnnotationsProcessor/src/main/java/com/christophecvb/touchportal/annotations/processor/utils/SpecUtils.java @@ -197,9 +197,28 @@ public static TypeSpec.Builder createSettingTypeSpecBuilder(Element settingEleme stateTypeSpecBuilder.addField(SpecUtils.getStaticFinalDoubleFieldSpec("max_value", setting.maxValue())); } + if (!setting.tooltip().body().isBlank()) { + stateTypeSpecBuilder.addType(createSettingTooltipTypeSpecBuilder(setting.tooltip()).build()); + } + return stateTypeSpecBuilder; } + /** + * Generates a TypeSpec.Builder with Constants for the {@link Setting.Tooltip} + * + * @param tooltip {@link Setting.Tooltip} + * @return TypeSpec.Builder tooltipTypeSpecBuilder + */ + public static TypeSpec.Builder createSettingTooltipTypeSpecBuilder(Setting.Tooltip tooltip) { + TypeSpec.Builder tooltipTypeSpecBuilder = TypeSpec.classBuilder("TOOLTIP").addModifiers(Modifier.PUBLIC, Modifier.STATIC); + tooltipTypeSpecBuilder.addField(SpecUtils.getStaticFinalStringFieldSpec("title", tooltip.title())); + tooltipTypeSpecBuilder.addField(SpecUtils.getStaticFinalStringFieldSpec("body", tooltip.body())); + tooltipTypeSpecBuilder.addField(SpecUtils.getStaticFinalStringFieldSpec("docUrl", tooltip.docUrl())); + + return tooltipTypeSpecBuilder; + } + /** * Generates a TypeSpec.Builder with Constants for the {@link State} * diff --git a/Helpers/src/main/java/com/christophecvb/touchportal/helpers/SettingHelper.java b/Helpers/src/main/java/com/christophecvb/touchportal/helpers/SettingHelper.java index e559e98..a78eff3 100644 --- a/Helpers/src/main/java/com/christophecvb/touchportal/helpers/SettingHelper.java +++ b/Helpers/src/main/java/com/christophecvb/touchportal/helpers/SettingHelper.java @@ -39,6 +39,13 @@ public class SettingHelper { public static final String MIN_VALUE = "minValue"; public static final String MAX_VALUE = "maxValue"; public static final String IS_READ_ONLY = "readOnly"; + public static final String TOOLTIP = "tooltip"; + + public static class Tooltip { + public static final String TITLE = "title"; + public static final String BODY = "body"; + public static final String DOC_URL = "docUrl"; + } /** * Get the generated Setting Name diff --git a/SampleJava/src/main/java/com/christophecvb/touchportal/samplejava/TouchPortalSampleJavaPlugin.java b/SampleJava/src/main/java/com/christophecvb/touchportal/samplejava/TouchPortalSampleJavaPlugin.java index 2737b69..0f96873 100644 --- a/SampleJava/src/main/java/com/christophecvb/touchportal/samplejava/TouchPortalSampleJavaPlugin.java +++ b/SampleJava/src/main/java/com/christophecvb/touchportal/samplejava/TouchPortalSampleJavaPlugin.java @@ -31,7 +31,6 @@ import java.io.File; import java.util.HashMap; -import java.util.Objects; import java.util.logging.Level; import java.util.logging.Logger; @@ -80,7 +79,11 @@ private enum Categories { /** * Setting of type text definition example */ - @Setting(name = "IP", defaultValue = "localhost", maxLength = 15) + @Setting(name = "IP", defaultValue = "localhost", maxLength = 15, tooltip = @Setting.Tooltip( + title = "IP address", + body = "ip address to connect to", + docUrl = "https://example.com" + )) private String ipSetting; /** From e3265b731f33600384877ae5b4efdd010f0dce0a Mon Sep 17 00:00:00 2001 From: Pjiesco Date: Fri, 6 Oct 2023 15:36:28 +0200 Subject: [PATCH 2/6] fix: use java 8 --- .../touchportal/annotations/processor/SettingProcessor.java | 2 +- .../touchportal/annotations/processor/utils/SpecUtils.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/AnnotationsProcessor/src/main/java/com/christophecvb/touchportal/annotations/processor/SettingProcessor.java b/AnnotationsProcessor/src/main/java/com/christophecvb/touchportal/annotations/processor/SettingProcessor.java index 1cbb81a..ee3fe66 100644 --- a/AnnotationsProcessor/src/main/java/com/christophecvb/touchportal/annotations/processor/SettingProcessor.java +++ b/AnnotationsProcessor/src/main/java/com/christophecvb/touchportal/annotations/processor/SettingProcessor.java @@ -35,7 +35,7 @@ public static Pair process(TouchPortalPluginAnnota jsonSetting.addProperty(SettingHelper.DEFAULT, setting.defaultValue()); jsonSetting.addProperty(SettingHelper.IS_READ_ONLY, setting.isReadOnly()); - if (!setting.tooltip().body().isBlank()) { + if (!setting.tooltip().body().isEmpty()) { JsonObject tooltip = new JsonObject(); tooltip.addProperty(SettingHelper.Tooltip.TITLE, setting.tooltip().title()); diff --git a/AnnotationsProcessor/src/main/java/com/christophecvb/touchportal/annotations/processor/utils/SpecUtils.java b/AnnotationsProcessor/src/main/java/com/christophecvb/touchportal/annotations/processor/utils/SpecUtils.java index 5f3ef7e..d3ec4c1 100644 --- a/AnnotationsProcessor/src/main/java/com/christophecvb/touchportal/annotations/processor/utils/SpecUtils.java +++ b/AnnotationsProcessor/src/main/java/com/christophecvb/touchportal/annotations/processor/utils/SpecUtils.java @@ -197,7 +197,7 @@ public static TypeSpec.Builder createSettingTypeSpecBuilder(Element settingEleme stateTypeSpecBuilder.addField(SpecUtils.getStaticFinalDoubleFieldSpec("max_value", setting.maxValue())); } - if (!setting.tooltip().body().isBlank()) { + if (!setting.tooltip().body().isEmpty()) { stateTypeSpecBuilder.addType(createSettingTooltipTypeSpecBuilder(setting.tooltip()).build()); } From a527952202346bbedc3d3ecafb1592b34da377cd Mon Sep 17 00:00:00 2001 From: Pjiesco Date: Sat, 7 Oct 2023 11:19:08 +0200 Subject: [PATCH 3/6] Remove empty lines --- .../touchportal/annotations/processor/SettingProcessor.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/AnnotationsProcessor/src/main/java/com/christophecvb/touchportal/annotations/processor/SettingProcessor.java b/AnnotationsProcessor/src/main/java/com/christophecvb/touchportal/annotations/processor/SettingProcessor.java index ee3fe66..a58e28d 100644 --- a/AnnotationsProcessor/src/main/java/com/christophecvb/touchportal/annotations/processor/SettingProcessor.java +++ b/AnnotationsProcessor/src/main/java/com/christophecvb/touchportal/annotations/processor/SettingProcessor.java @@ -77,8 +77,6 @@ public static Pair process(TouchPortalPluginAnnota throw new GenericHelper.TPTypeException.Builder(className).typeUnsupported(desiredTPType).forAnnotation(GenericHelper.TPTypeException.ForAnnotation.SETTING).build(); } - - return Pair.create(jsonSetting, settingTypeSpecBuilder); } } From 908fcfee3f6de8096e5619072b53a95d35057589 Mon Sep 17 00:00:00 2001 From: Pjiesco Date: Sat, 7 Oct 2023 11:31:23 +0200 Subject: [PATCH 4/6] Check if empty --- .../annotations/processor/SettingProcessor.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/AnnotationsProcessor/src/main/java/com/christophecvb/touchportal/annotations/processor/SettingProcessor.java b/AnnotationsProcessor/src/main/java/com/christophecvb/touchportal/annotations/processor/SettingProcessor.java index a58e28d..6e27f22 100644 --- a/AnnotationsProcessor/src/main/java/com/christophecvb/touchportal/annotations/processor/SettingProcessor.java +++ b/AnnotationsProcessor/src/main/java/com/christophecvb/touchportal/annotations/processor/SettingProcessor.java @@ -38,9 +38,14 @@ public static Pair process(TouchPortalPluginAnnota if (!setting.tooltip().body().isEmpty()) { JsonObject tooltip = new JsonObject(); - tooltip.addProperty(SettingHelper.Tooltip.TITLE, setting.tooltip().title()); tooltip.addProperty(SettingHelper.Tooltip.BODY, setting.tooltip().body()); - tooltip.addProperty(SettingHelper.Tooltip.DOC_URL, setting.tooltip().docUrl()); + + if (!setting.tooltip().title().isEmpty()) { + tooltip.addProperty(SettingHelper.Tooltip.TITLE, setting.tooltip().title()); + } + if (!setting.tooltip().docUrl().isEmpty()) { + tooltip.addProperty(SettingHelper.Tooltip.DOC_URL, setting.tooltip().docUrl()); + } jsonSetting.add(SettingHelper.TOOLTIP, tooltip); } From 49f8d522338de4e125c53696b9a71130d3b4419c Mon Sep 17 00:00:00 2001 From: Pjiesco Date: Sat, 7 Oct 2023 19:59:43 +0200 Subject: [PATCH 5/6] use UpperCamelCase instead of Full uppercase --- .../touchportal/annotations/processor/utils/SpecUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AnnotationsProcessor/src/main/java/com/christophecvb/touchportal/annotations/processor/utils/SpecUtils.java b/AnnotationsProcessor/src/main/java/com/christophecvb/touchportal/annotations/processor/utils/SpecUtils.java index d3ec4c1..1d73d1e 100644 --- a/AnnotationsProcessor/src/main/java/com/christophecvb/touchportal/annotations/processor/utils/SpecUtils.java +++ b/AnnotationsProcessor/src/main/java/com/christophecvb/touchportal/annotations/processor/utils/SpecUtils.java @@ -211,7 +211,7 @@ public static TypeSpec.Builder createSettingTypeSpecBuilder(Element settingEleme * @return TypeSpec.Builder tooltipTypeSpecBuilder */ public static TypeSpec.Builder createSettingTooltipTypeSpecBuilder(Setting.Tooltip tooltip) { - TypeSpec.Builder tooltipTypeSpecBuilder = TypeSpec.classBuilder("TOOLTIP").addModifiers(Modifier.PUBLIC, Modifier.STATIC); + TypeSpec.Builder tooltipTypeSpecBuilder = TypeSpec.classBuilder("Tooltip").addModifiers(Modifier.PUBLIC, Modifier.STATIC); tooltipTypeSpecBuilder.addField(SpecUtils.getStaticFinalStringFieldSpec("title", tooltip.title())); tooltipTypeSpecBuilder.addField(SpecUtils.getStaticFinalStringFieldSpec("body", tooltip.body())); tooltipTypeSpecBuilder.addField(SpecUtils.getStaticFinalStringFieldSpec("docUrl", tooltip.docUrl())); From 908a769fb0a98153a467ee74f223bb2e8e3ec24d Mon Sep 17 00:00:00 2001 From: Pjiesco Date: Mon, 9 Oct 2023 12:21:52 +0200 Subject: [PATCH 6/6] Check if empty --- .../annotations/processor/utils/SpecUtils.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/AnnotationsProcessor/src/main/java/com/christophecvb/touchportal/annotations/processor/utils/SpecUtils.java b/AnnotationsProcessor/src/main/java/com/christophecvb/touchportal/annotations/processor/utils/SpecUtils.java index 1d73d1e..044022f 100644 --- a/AnnotationsProcessor/src/main/java/com/christophecvb/touchportal/annotations/processor/utils/SpecUtils.java +++ b/AnnotationsProcessor/src/main/java/com/christophecvb/touchportal/annotations/processor/utils/SpecUtils.java @@ -212,10 +212,13 @@ public static TypeSpec.Builder createSettingTypeSpecBuilder(Element settingEleme */ public static TypeSpec.Builder createSettingTooltipTypeSpecBuilder(Setting.Tooltip tooltip) { TypeSpec.Builder tooltipTypeSpecBuilder = TypeSpec.classBuilder("Tooltip").addModifiers(Modifier.PUBLIC, Modifier.STATIC); - tooltipTypeSpecBuilder.addField(SpecUtils.getStaticFinalStringFieldSpec("title", tooltip.title())); tooltipTypeSpecBuilder.addField(SpecUtils.getStaticFinalStringFieldSpec("body", tooltip.body())); - tooltipTypeSpecBuilder.addField(SpecUtils.getStaticFinalStringFieldSpec("docUrl", tooltip.docUrl())); - + if (!tooltip.title().isEmpty()) { + tooltipTypeSpecBuilder.addField(SpecUtils.getStaticFinalStringFieldSpec("title", tooltip.title())); + } + if (!tooltip.title().isEmpty()) { + tooltipTypeSpecBuilder.addField(SpecUtils.getStaticFinalStringFieldSpec("docUrl", tooltip.docUrl())); + } return tooltipTypeSpecBuilder; }