From 1c4f52f1b143923efb836c252e7f2390caeb5391 Mon Sep 17 00:00:00 2001 From: Jake Berg Date: Sat, 16 Aug 2025 17:14:36 +0100 Subject: [PATCH] #5 add support for using custom tick text --- .../visualticks/BaseVisualTicksOverlay.java | 25 ++++++- .../com/visualticks/VisualTicksConfig.java | 66 +++++++++++++++++-- .../visualticks/VisualTicksOverlayOne.java | 6 ++ .../visualticks/VisualTicksOverlayThree.java | 6 ++ .../visualticks/VisualTicksOverlayTwo.java | 6 ++ 5 files changed, 101 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/visualticks/BaseVisualTicksOverlay.java b/src/main/java/com/visualticks/BaseVisualTicksOverlay.java index 5d7a419..30b0bb6 100644 --- a/src/main/java/com/visualticks/BaseVisualTicksOverlay.java +++ b/src/main/java/com/visualticks/BaseVisualTicksOverlay.java @@ -11,6 +11,7 @@ import java.awt.*; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; public abstract class BaseVisualTicksOverlay extends Overlay @@ -51,6 +52,25 @@ public void onConfigChanged() { protected abstract Color getCurrentTickTextColour(); protected abstract TickShape getTickShape(); protected abstract int getTickArc(); + protected abstract boolean shouldShowCustomText(); + protected abstract String getCustomTickText(); + + protected String[] customTickText; + + protected String getTickText(int tickIndex){ + String tickText = String.valueOf(tickIndex + 1); + if (shouldShowCustomText()){ + if (customTickText.length > tickIndex){ + tickText = customTickText[tickIndex]; + } + } + return tickText; + } + + protected void calculateCustomTickText() { + configChanged = false; + customTickText = Arrays.stream(getCustomTickText().split(",")).map(String::trim).toArray(String[]::new); + } protected void calculateSizes(Graphics2D g) { configChanged = false; @@ -71,7 +91,7 @@ protected void calculateSizes(Graphics2D g) { { int boundingSize = shouldShowTickShape() ? shapeSize : 0; - String text = String.valueOf(i + 1); + String text = getTickText(i); int textWidth = fm.stringWidth(text); int textHeight = fm.getAscent(); @@ -107,6 +127,7 @@ protected void calculateSizes(Graphics2D g) { public Dimension render(Graphics2D graphics) { if(configChanged) { + calculateCustomTickText(); calculateSizes(graphics); } @@ -135,7 +156,7 @@ public Dimension render(Graphics2D graphics) } if (shouldShowText()) { graphics.setColor(i == getCurrentTick() ? getCurrentTickTextColour() : getTickTextColour()); - graphics.drawString(String.valueOf(i + 1), tick.getFontX(), tick.getFontY()); + graphics.drawString(getTickText(i), tick.getFontX(), tick.getFontY()); } } diff --git a/src/main/java/com/visualticks/VisualTicksConfig.java b/src/main/java/com/visualticks/VisualTicksConfig.java index d790129..255dd97 100644 --- a/src/main/java/com/visualticks/VisualTicksConfig.java +++ b/src/main/java/com/visualticks/VisualTicksConfig.java @@ -199,12 +199,30 @@ default Color currentTickTextColourOne() { return new Color(41, 128, 185); } + @ConfigItem( + keyName = "shouldShowCustomTextOne", + name = "Show custom text", + description = "Show custom text of the current tick", + section = tickSettings, + position = 14 + ) + default boolean shouldShowCustomTextOne() { return false; } + + @ConfigItem( + keyName = "customTextOne", + name = "Custom text", + description = "Custom text to show on each tick, separated by commas", + section = tickSettings, + position = 15 + ) + default String customTextOne() { return "1,2,3"; } + @ConfigItem( keyName = "horizontalSpacingOne", name = "Horizontal spacing", description = "The amount of space between ticks on the x-axis", section = tickSettings, - position = 14 + position = 16 ) @Range(min = -50) default int horizontalSpacingOne() { @@ -216,7 +234,7 @@ default int horizontalSpacingOne() { name = "Vertical spacing", description = "The amount of space between ticks on the y-axis", section = tickSettings, - position = 15 + position = 17 ) @Range(min = -50) default int verticalSpacingOne() { @@ -394,12 +412,30 @@ default Color currentTickTextColourTwo() { return new Color(41, 128, 185); } + @ConfigItem( + keyName = "shouldShowCustomTextTwo", + name = "Show custom text", + description = "Show custom text of the current tick", + section = tickSettingsTwo, + position = 14 + ) + default boolean shouldShowCustomTextTwo() { return false; } + + @ConfigItem( + keyName = "customTextTwo", + name = "Custom text", + description = "Custom text to show on each tick, separated by commas", + section = tickSettingsTwo, + position = 15 + ) + default String customTextTwo() { return "1,2,3"; } + @ConfigItem( keyName = "horizontalSpacingTwo", name = "Horizontal spacing", description = "The amount of space between ticks on the x-axis", section = tickSettingsTwo, - position = 14 + position = 16 ) @Range(min = -50) default int horizontalSpacingTwo() { @@ -411,7 +447,7 @@ default int horizontalSpacingTwo() { name = "Vertical spacing", description = "The amount of space between ticks on the y-axis", section = tickSettingsTwo, - position = 15 + position = 17 ) @Range(min = -50) default int verticalSpacingTwo() { @@ -589,12 +625,30 @@ default Color currentTickTextColourThree() { return new Color(41, 128, 185); } + @ConfigItem( + keyName = "shouldShowCustomTextThree", + name = "Show custom text", + description = "Show custom text of the current tick", + section = tickSettingsThree, + position = 14 + ) + default boolean shouldShowCustomTextThree() { return false; } + + @ConfigItem( + keyName = "customTextThree", + name = "Custom text", + description = "Custom text to show on each tick, separated by commas", + section = tickSettingsThree, + position = 15 + ) + default String customTextThree() { return "1,2,3"; } + @ConfigItem( keyName = "horizontalSpacingThree", name = "Horizontal spacing", description = "The amount of space between ticks on the x-axis", section = tickSettingsThree, - position = 14 + position = 16 ) @Range(min = -50) default int horizontalSpacingThree() { @@ -606,7 +660,7 @@ default int horizontalSpacingThree() { name = "Vertical spacing", description = "The amount of space between ticks on the y-axis", section = tickSettingsThree, - position = 15 + position = 17 ) @Range(min = -50) default int verticalSpacingThree() { diff --git a/src/main/java/com/visualticks/VisualTicksOverlayOne.java b/src/main/java/com/visualticks/VisualTicksOverlayOne.java index 68300d5..962e330 100644 --- a/src/main/java/com/visualticks/VisualTicksOverlayOne.java +++ b/src/main/java/com/visualticks/VisualTicksOverlayOne.java @@ -95,4 +95,10 @@ protected TickShape getTickShape() { protected int getTickArc() { return config.tickArcOne(); } + + @Override + protected boolean shouldShowCustomText() { return config.shouldShowCustomTextOne(); } + + @Override + protected String getCustomTickText() { return config.customTextOne(); } } diff --git a/src/main/java/com/visualticks/VisualTicksOverlayThree.java b/src/main/java/com/visualticks/VisualTicksOverlayThree.java index 1261312..3535701 100644 --- a/src/main/java/com/visualticks/VisualTicksOverlayThree.java +++ b/src/main/java/com/visualticks/VisualTicksOverlayThree.java @@ -95,4 +95,10 @@ protected TickShape getTickShape() { protected int getTickArc() { return config.tickArcThree(); } + + @Override + protected boolean shouldShowCustomText() { return config.shouldShowCustomTextThree(); } + + @Override + protected String getCustomTickText() { return config.customTextThree(); } } diff --git a/src/main/java/com/visualticks/VisualTicksOverlayTwo.java b/src/main/java/com/visualticks/VisualTicksOverlayTwo.java index d171991..ecaa3ae 100644 --- a/src/main/java/com/visualticks/VisualTicksOverlayTwo.java +++ b/src/main/java/com/visualticks/VisualTicksOverlayTwo.java @@ -95,4 +95,10 @@ protected TickShape getTickShape() { protected int getTickArc() { return config.tickArcTwo(); } + + @Override + protected boolean shouldShowCustomText() { return config.shouldShowCustomTextTwo(); } + + @Override + protected String getCustomTickText() { return config.customTextTwo(); } }