0537bbedfaa2991894ba4d4f7a034d8f1e305dd3
2 * Jexer - Java Text User Interface
4 * License: LGPLv3 or later
6 * This module is licensed under the GNU Lesser General Public License
7 * Version 3. Please see the file "COPYING" in this directory for more
8 * information about the GNU Lesser General Public License Version 3.
10 * Copyright (C) 2015 Kevin Lamonte
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public License
14 * as published by the Free Software Foundation; either version 3 of
15 * the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this program; if not, see
24 * http://www.gnu.org/licenses/, or write to the Free Software
25 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
28 * @author Kevin Lamonte [kevin.lamonte@gmail.com]
34 * MnemonicString is used to render a string like "&File" into a highlighted
35 * 'F' and the rest of 'ile'. To insert a literal '&', use two '&&'
36 * characters, e.g. "&File && Stuff" would be "File & Stuff" with the first
39 public class MnemonicString
{
42 * Keyboard shortcut to activate this item.
44 private char shortcut
;
47 * Location of the highlighted character.
49 private int shortcutIdx
= -1;
52 * The raw (uncolored) string.
54 private String rawLabel
;
59 * @param label widget label or title. Label must contain a keyboard
60 * shortcut, denoted by prefixing a letter with "&", e.g. "&File"
62 public MnemonicString(final String label
) {
64 // Setup the menu shortcut
66 boolean foundAmp
= false;
67 boolean foundShortcut
= false;
68 int scanShortcutIdx
= 0;
69 for (int i
= 0; i
< label
.length(); i
++) {
70 char c
= label
.charAt(i
);
85 shortcutIdx
= scanShortcutIdx
;
92 this.rawLabel
= newLabel
;