Skip to content

Commit fff932e

Browse files
committed
feat: improved profile visualization symbology
1 parent 03342d8 commit fff932e

File tree

5 files changed

+58
-56
lines changed

5 files changed

+58
-56
lines changed

src/main/java/de/bwravencl/controllerbuddy/gui/Main.java

Lines changed: 55 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,10 @@
4242
import de.bwravencl.controllerbuddy.input.action.ButtonToModeAction;
4343
import de.bwravencl.controllerbuddy.input.action.IAction;
4444
import de.bwravencl.controllerbuddy.input.action.IActivatableAction;
45-
import de.bwravencl.controllerbuddy.input.action.IActivatableAction.Activation;
4645
import de.bwravencl.controllerbuddy.input.action.ILongPressAction;
4746
import de.bwravencl.controllerbuddy.input.action.ToAxisAction;
47+
import de.bwravencl.controllerbuddy.input.action.ToCursorAction;
48+
import de.bwravencl.controllerbuddy.input.action.ToScrollAction;
4849
import de.bwravencl.controllerbuddy.json.ActionTypeAdapter;
4950
import de.bwravencl.controllerbuddy.json.ColorTypeAdapter;
5051
import de.bwravencl.controllerbuddy.json.LockKeyAdapter;
@@ -128,6 +129,9 @@
128129
import java.time.format.DateTimeFormatter;
129130
import java.time.format.FormatStyle;
130131
import java.util.ArrayList;
132+
import java.util.Arrays;
133+
import java.util.Collection;
134+
import java.util.Collections;
131135
import java.util.Comparator;
132136
import java.util.EnumMap;
133137
import java.util.EnumSet;
@@ -1887,20 +1891,17 @@ private int addTSpanElement(final List<? extends IAction<?>> actions, final Node
18871891
var description = action.getDescription(input);
18881892

18891893
if (action instanceof final ButtonToModeAction buttonToModeAction) {
1890-
description = (buttonToModeAction.isToggle() ? "⇪" : "⇧") + " " + description;
1894+
description = description + " " + (buttonToModeAction.isToggle() ? "⇪" : "⇧");
18911895
}
18921896

18931897
return description;
1894-
}).distinct().collect(Collectors.joining(", ")), false, parentNode);
1898+
}).distinct().collect(Collectors.joining(", ")), parentNode);
18951899
}
18961900

1897-
private int addTSpanElement(final String textContent, final boolean bold, final Node parentNode) {
1901+
private int addTSpanElement(final String textContent, final Node parentNode) {
18981902
final var prefixTSpanElement = parentNode.getOwnerDocument().createElementNS("http://www.w3.org/2000/svg",
18991903
"tspan");
19001904

1901-
if (bold) {
1902-
prefixTSpanElement.setAttribute("style", "font-weight: bold");
1903-
}
19041905
prefixTSpanElement.setTextContent(textContent);
19051906
parentNode.appendChild(prefixTSpanElement);
19061907

@@ -1948,7 +1949,7 @@ private int addTSpanElement(final String textContent, final boolean bold, final
19481949
}
19491950
}
19501951

1951-
final var font = new Font(fontFamily, bold ? Font.BOLD : Font.PLAIN, fontSizePt);
1952+
final var font = new Font(fontFamily, Font.PLAIN, fontSizePt);
19521953
final var fontMetrics = frame.getFontMetrics(font);
19531954

19541955
final var extensionWidth = fontMetrics.stringWidth(textContent);
@@ -4293,43 +4294,61 @@ private int updateSvgElements(final Document svgDocument, final String idPrefix,
42934294
}
42944295

42954296
final var delayedActions = new ArrayList<ILongPressAction<?>>();
4297+
final var whilePressedActions = new ArrayList<IActivatableAction<?>>();
4298+
final var onPressActions = new ArrayList<IActivatableAction<?>>();
42964299
final var onReleaseActions = new ArrayList<IActivatableAction<?>>();
42974300
final var otherActions = new ArrayList<IAction<?>>();
42984301

42994302
for (final var action : actions) {
4300-
var addToOtherActions = true;
4301-
43024303
if (action instanceof final ILongPressAction<?> longPressAction && longPressAction.isLongPress()) {
43034304
delayedActions.add(longPressAction);
4304-
addToOtherActions = false;
4305-
}
4306-
if (action instanceof final IActivatableAction<?> activatableAction
4307-
&& activatableAction.getActivation() == Activation.ON_RELEASE) {
4308-
onReleaseActions.add(activatableAction);
4309-
addToOtherActions = false;
4310-
}
4311-
4312-
if (addToOtherActions) {
4305+
} else if (action instanceof final IActivatableAction<?> activatableAction) {
4306+
switch (activatableAction.getActivation()) {
4307+
case WHILE_PRESSED -> whilePressedActions.add(activatableAction);
4308+
case ON_PRESS -> onPressActions.add(activatableAction);
4309+
case ON_RELEASE -> onReleaseActions.add(activatableAction);
4310+
}
4311+
} else {
43134312
otherActions.add(action);
43144313
}
43154314
}
43164315

43174316
final List<? extends IAction<?>> actionGroupA;
4318-
final List<? extends IAction<?>> actionGroupB;
4317+
List<? extends IAction<?>> actionGroupB;
4318+
List<? extends IAction<?>> actionGroupC;
43194319
final String groupAPrefix;
4320-
final String groupBPrefix;
4320+
String groupBPrefix;
4321+
String groupCPrefix;
43214322

43224323
// noinspection SuspiciousMethodCalls
43234324
if (delayedActions.isEmpty() || delayedActions.containsAll(actions)) {
4324-
actionGroupA = Stream.concat(otherActions.stream(), delayedActions.stream()).toList();
4325-
actionGroupB = onReleaseActions;
4326-
groupAPrefix = "VISUALIZATION_ON_PRESS_PREFIX";
4327-
groupBPrefix = "VISUALIZATION_ON_RELEASE_PREFIX";
4325+
final var partitionedNonActivateableActionsMap = Stream.of( otherActions, delayedActions).flatMap(Collection::stream).collect(Collectors.partitioningBy(action -> switch (action) {
4326+
case final ButtonToModeAction buttonToModeAction -> !buttonToModeAction.isToggle();
4327+
case final ToAxisAction<?> _, final ToCursorAction<?> _, final ToScrollAction<?> _ -> true;
4328+
default -> false;
4329+
}));
4330+
4331+
actionGroupA = Stream.of(onPressActions, partitionedNonActivateableActionsMap.get(false)).flatMap(Collection::stream).toList();
4332+
actionGroupB = Stream.of(whilePressedActions, partitionedNonActivateableActionsMap.get(true)).flatMap(Collection::stream).toList();
4333+
actionGroupC = onReleaseActions;
4334+
groupAPrefix = "⤓";
4335+
groupBPrefix = "↦";
4336+
groupCPrefix = "⤒";
43284337
} else {
4329-
actionGroupA = Stream.concat(otherActions.stream(), onReleaseActions.stream()).toList();
4338+
actionGroupA = Stream.of(onPressActions, whilePressedActions, onReleaseActions).flatMap(Collection::stream)
4339+
.toList();
43304340
actionGroupB = delayedActions;
4331-
groupAPrefix = "VISUALIZATION_SHORT_PREFIX";
4332-
groupBPrefix = "VISUALIZATION_LONG_PREFIX";
4341+
actionGroupC = Collections.emptyList();
4342+
groupAPrefix = "➧";
4343+
groupBPrefix = "➡";
4344+
groupCPrefix = null;
4345+
}
4346+
4347+
if (actionGroupB.isEmpty() && !actionGroupC.isEmpty()) {
4348+
actionGroupB = actionGroupC;
4349+
actionGroupC = Collections.emptyList();
4350+
groupBPrefix = groupCPrefix;
4351+
groupCPrefix = null;
43334352
}
43344353

43354354
final var groupBPresent = !actionGroupB.isEmpty();
@@ -4345,19 +4364,24 @@ private int updateSvgElements(final Document svgDocument, final String idPrefix,
43454364
var extensionWidth = 0;
43464365

43474366
if (bothGroupsPresent) {
4348-
extensionWidth += addTSpanElement("• " + STRINGS.getString(groupAPrefix) + ": ", true, tSpanNode);
4367+
extensionWidth += addTSpanElement(groupAPrefix + " ", tSpanNode);
43494368
}
43504369

43514370
extensionWidth += addTSpanElement(actionGroupA, tSpanNode);
43524371

43534372
if (bothGroupsPresent) {
4354-
extensionWidth += addTSpanElement("" + STRINGS.getString(groupBPrefix) + ": ", true, tSpanNode);
4373+
extensionWidth += addTSpanElement("" + groupBPrefix + " ", tSpanNode);
43554374
}
43564375

43574376
extensionWidth += addTSpanElement(actionGroupB, tSpanNode);
43584377

4378+
if (!actionGroupC.isEmpty()) {
4379+
extensionWidth += addTSpanElement(" " + groupCPrefix + " ", tSpanNode);
4380+
extensionWidth += addTSpanElement(actionGroupC, tSpanNode);
4381+
}
4382+
43594383
if (swapped) {
4360-
extensionWidth += addTSpanElement(" " + SWAPPED_SYMBOL, true, tSpanNode);
4384+
extensionWidth += addTSpanElement("" + SWAPPED_SYMBOL, tSpanNode);
43614385
}
43624386

43634387
if (darkTheme) {

src/main/java/de/bwravencl/controllerbuddy/input/action/ButtonToCycleAction.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,13 @@
1616

1717
package de.bwravencl.controllerbuddy.input.action;
1818

19-
import de.bwravencl.controllerbuddy.gui.Main;
2019
import de.bwravencl.controllerbuddy.input.Input;
2120
import de.bwravencl.controllerbuddy.input.action.annotation.Action;
2221
import de.bwravencl.controllerbuddy.input.action.annotation.Action.ActionCategory;
2322
import de.bwravencl.controllerbuddy.input.action.annotation.ActionProperty;
2423
import de.bwravencl.controllerbuddy.input.action.gui.ActionsEditorBuilder;
2524
import de.bwravencl.controllerbuddy.input.action.gui.ActivationEditorBuilder;
2625
import de.bwravencl.controllerbuddy.input.action.gui.LongPressEditorBuilder;
27-
import java.text.MessageFormat;
2826
import java.util.ArrayList;
2927
import java.util.List;
3028
import java.util.stream.Collectors;
@@ -125,8 +123,8 @@ public String getDescription(final Input input) {
125123
return super.getDescription(input);
126124
}
127125

128-
return MessageFormat.format(Main.STRINGS.getString("CYCLE"),
129-
actions.stream().map(action -> action.getDescription(input)).collect(Collectors.joining(" → ")));
126+
return actions.stream().map(action -> action.getDescription(input))
127+
.collect(Collectors.joining(" → ", "\uD83D\uDDD8 ", " ↺"));
130128
}
131129

132130
@Override

src/main/java/de/bwravencl/controllerbuddy/input/action/ToScrollAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import java.text.MessageFormat;
2525
import java.util.Locale;
2626

27-
abstract class ToScrollAction<V extends Constable> extends InvertableAction<V> {
27+
public abstract class ToScrollAction<V extends Constable> extends InvertableAction<V> {
2828

2929
private static final int DEFAULT_CLICKS = 10;
3030

src/main/resources/strings.properties

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -431,15 +431,5 @@ MOUSE_BUTTON_NO = Mouse Button {0,number,integer}
431431
SCROLL_DIRECTION = Scroll {0}
432432
LOCK_KEY_ON = {0} on
433433
LOCK_KEY_OFF = {0} off
434-
CYCLE = Cycle [{0}]
435434

436435
NOTHING = nothing
437-
438-
# suppress inspection "UnusedProperty"
439-
VISUALIZATION_SHORT_PREFIX = Short
440-
# suppress inspection "UnusedProperty"
441-
VISUALIZATION_LONG_PREFIX = Long
442-
# suppress inspection "UnusedProperty"
443-
VISUALIZATION_ON_PRESS_PREFIX = Press
444-
# suppress inspection "UnusedProperty"
445-
VISUALIZATION_ON_RELEASE_PREFIX = Release

src/main/resources/strings_de_DE.properties

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -399,15 +399,5 @@ MOUSE_BUTTON_NO = Maustaste {0,number,integer}
399399
SCROLL_DIRECTION = {0} scrollen
400400
LOCK_KEY_ON = {0} an
401401
LOCK_KEY_OFF = {0} aus
402-
CYCLE = Zyklus [{0}]
403402

404403
NOTHING = nichts
405-
406-
# suppress inspection "UnusedProperty"
407-
VISUALIZATION_SHORT_PREFIX = Kurz
408-
# suppress inspection "UnusedProperty"
409-
VISUALIZATION_LONG_PREFIX = Lang
410-
# suppress inspection "UnusedProperty"
411-
VISUALIZATION_ON_PRESS_PREFIX = Drücken
412-
# suppress inspection "UnusedProperty"
413-
VISUALIZATION_ON_RELEASE_PREFIX = Loslassen

0 commit comments

Comments
 (0)