*
* The MIT License (MIT)
*
- * Copyright (C) 2017 Kevin Lamonte
+ * Copyright (C) 2019 Kevin Lamonte
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* two '&&' characters, e.g. "&File && Stuff" would be
* "File & Stuff" with the first 'F' highlighted.
*/
-public final class MnemonicString {
+public class MnemonicString {
// ------------------------------------------------------------------------
// Variables --------------------------------------------------------------
*/
private int shortcutIdx = -1;
+ /**
+ * Screen location of the highlighted character (number of text cells
+ * required to display from the beginning to shortcutIdx).
+ */
+ private int screenShortcutIdx = -1;
+
/**
* The raw (uncolored) string.
*/
boolean foundAmp = false;
boolean foundShortcut = false;
int scanShortcutIdx = 0;
+ int scanScreenShortcutIdx = 0;
for (int i = 0; i < label.length(); i++) {
char c = label.charAt(i);
if (c == '&') {
if (foundAmp) {
newLabel += '&';
scanShortcutIdx++;
+ scanScreenShortcutIdx++;
} else {
foundAmp = true;
}
foundAmp = false;
foundShortcut = true;
shortcutIdx = scanShortcutIdx;
+ screenShortcutIdx = scanScreenShortcutIdx;
}
} else {
scanShortcutIdx++;
+ scanScreenShortcutIdx += StringUtils.width(c);
}
}
}
return shortcutIdx;
}
+ /**
+ * Get the screen location of the highlighted character.
+ *
+ * @return the number of text cells required to display from the
+ * beginning of the label to shortcutIdx
+ */
+ public int getScreenShortcutIdx() {
+ return screenShortcutIdx;
+ }
+
/**
* Get the raw (uncolored) string.
*