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..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 @@ -34,6 +34,22 @@ 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().isEmpty()) { + JsonObject tooltip = new JsonObject(); + + tooltip.addProperty(SettingHelper.Tooltip.BODY, setting.tooltip().body()); + + 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); + } + switch (desiredTPType) { case SettingHelper.TYPE_TEXT: if (setting.maxLength() > 0) { 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..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 @@ -197,9 +197,31 @@ public static TypeSpec.Builder createSettingTypeSpecBuilder(Element settingEleme stateTypeSpecBuilder.addField(SpecUtils.getStaticFinalDoubleFieldSpec("max_value", setting.maxValue())); } + if (!setting.tooltip().body().isEmpty()) { + 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("body", tooltip.body())); + if (!tooltip.title().isEmpty()) { + tooltipTypeSpecBuilder.addField(SpecUtils.getStaticFinalStringFieldSpec("title", tooltip.title())); + } + if (!tooltip.title().isEmpty()) { + 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; /**