/**
* Jexer - Java Text User Interface
*
- * Version: $Id$
- *
- * Author: Kevin Lamonte, <a href="mailto:kevin.lamonte@gmail.com">kevin.lamonte@gmail.com</a>
- *
* License: LGPLv3 or later
*
- * Copyright: This module is licensed under the GNU Lesser General
- * Public License Version 3. Please see the file "COPYING" in this
- * directory for more information about the GNU Lesser General Public
- * License Version 3.
+ * This module is licensed under the GNU Lesser General Public License
+ * Version 3. Please see the file "COPYING" in this directory for more
+ * information about the GNU Lesser General Public License Version 3.
*
* Copyright (C) 2015 Kevin Lamonte
*
* http://www.gnu.org/licenses/, or write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
+ *
+ * @author Kevin Lamonte [kevin.lamonte@gmail.com]
+ * @version 1
*/
package jexer.bits;
* characters, e.g. "&File && Stuff" would be "File & Stuff" with the first
* 'F' highlighted.
*/
-public class MnemonicString {
+public final class MnemonicString {
+
+ /**
+ * Keyboard shortcut to activate this item.
+ */
+ private char shortcut;
+
+ /**
+ * Get the keyboard shortcut character.
+ *
+ * @return the highlighted character
+ */
+ public char getShortcut() {
+ return shortcut;
+ }
/**
- * Keyboard shortcut to activate this item
+ * Location of the highlighted character.
*/
- public char shortcut;
+ private int shortcutIdx = -1;
/**
- * Location of the highlighted character
+ * Get location of the highlighted character.
+ *
+ * @return location of the highlighted character
*/
- public int shortcutIdx = -1;
+ public int getShortcutIdx() {
+ return shortcutIdx;
+ }
/**
- * The raw (uncolored) string
+ * The raw (uncolored) string.
*/
- public String rawLabel;
+ private String rawLabel;
/**
- * Public constructor
+ * Get the raw (uncolored) string.
+ *
+ * @return the raw (uncolored) string
+ */
+ public String getRawLabel() {
+ return rawLabel;
+ }
+
+ /**
+ * Public constructor.
*
* @param label widget label or title. Label must contain a keyboard
* shortcut, denoted by prefixing a letter with "&", e.g. "&File"
*/
- public MnemonicString(String label) {
+ public MnemonicString(final 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;
+ // Setup the menu shortcut
+ String newLabel = "";
+ boolean foundAmp = false;
+ boolean foundShortcut = false;
+ int scanShortcutIdx = 0;
+ for (int i = 0; i < label.length(); i++) {
+ char c = label.charAt(i);
+ if (c == '&') {
+ if (foundAmp) {
+ newLabel += '&';
+ scanShortcutIdx++;
+ } else {
+ foundAmp = true;
+ }
+ } else {
+ newLabel += c;
+ if (foundAmp) {
+ if (!foundShortcut) {
+ shortcut = c;
+ foundAmp = false;
+ foundShortcut = true;
+ shortcutIdx = scanShortcutIdx;
+ }
+ } else {
+ scanShortcutIdx++;
+ }
+ }
+ }
+ this.rawLabel = newLabel;
}
}
-