- public MnemonicString(String label) {
-
- // Setup the menu shortcut
- String newLabel = "";
- boolean foundAmp = false;
- boolean foundShortcut = false;
- int shortcutIdx = 0;
- for (int i = 0; i < label.length(); i++) {
- char c = label.charAt(i);
- if (c == '&') {
- if (foundAmp == true) {
- newLabel += '&';
- shortcutIdx++;
- } else {
- foundAmp = true;
- }
- } else {
- newLabel += c;
- if (foundAmp == true) {
- if (foundShortcut == false) {
- shortcut = c;
- foundAmp = false;
- foundShortcut = true;
- this.shortcutIdx = shortcutIdx;
- }
- } else {
- shortcutIdx++;
- }
- }
- }
- this.rawLabel = newLabel;
+ public MnemonicString(final String label) {
+
+ // Setup the menu shortcut
+ StringBuilder newLabel = new StringBuilder();
+ boolean foundAmp = false;
+ boolean foundShortcut = false;
+ int scanShortcutIdx = 0;
+ int scanScreenShortcutIdx = 0;
+ for (int i = 0; i < label.length();) {
+ int c = label.codePointAt(i);
+ i += Character.charCount(c);
+
+ if (c == '&') {
+ if (foundAmp) {
+ newLabel.append('&');
+ scanShortcutIdx++;
+ scanScreenShortcutIdx++;
+ } else {
+ foundAmp = true;
+ }
+ } else {
+ newLabel.append(Character.toChars(c));
+ if (foundAmp) {
+ if (!foundShortcut) {
+ shortcut = c;
+ foundAmp = false;
+ foundShortcut = true;
+ shortcutIdx = scanShortcutIdx;
+ screenShortcutIdx = scanScreenShortcutIdx;
+ }
+ } else {
+ scanShortcutIdx++;
+ scanScreenShortcutIdx += StringUtils.width(c);
+ }
+ }
+ }
+ this.rawLabel = newLabel.toString();
+ }
+
+ // ------------------------------------------------------------------------
+ // MnemonicString ---------------------------------------------------------
+ // ------------------------------------------------------------------------
+
+ /**
+ * Get the keyboard shortcut character.
+ *
+ * @return the highlighted character
+ */
+ public int getShortcut() {
+ return shortcut;