X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fjexer%2Fbits%2FMnemonicString.java;h=0537bbedfaa2991894ba4d4f7a034d8f1e305dd3;hb=7b5261bc5b641e0769902f014e3b21f61050b02b;hp=0567c99def9872045535d721e524667c612add2f;hpb=9edb442b712de01d1b7af81d1d57a29c2c6e7871;p=fanfix.git diff --git a/src/jexer/bits/MnemonicString.java b/src/jexer/bits/MnemonicString.java index 0567c99..0537bbe 100644 --- a/src/jexer/bits/MnemonicString.java +++ b/src/jexer/bits/MnemonicString.java @@ -1,16 +1,11 @@ /** * Jexer - Java Text User Interface * - * Version: $Id$ - * - * Author: Kevin Lamonte, kevin.lamonte@gmail.com - * * 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 * @@ -29,6 +24,9 @@ * 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; @@ -41,57 +39,56 @@ package jexer.bits; public class MnemonicString { /** - * Keyboard shortcut to activate this item + * Keyboard shortcut to activate this item. */ - public char shortcut; + private char shortcut; /** - * Location of the highlighted character + * Location of the highlighted character. */ - public int shortcutIdx = -1; + private int shortcutIdx = -1; /** - * The raw (uncolored) string + * The raw (uncolored) string. */ - public String rawLabel; + private String rawLabel; /** - * Public constructor + * 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; } } -