X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fjexer%2FTCheckBox.java;fp=src%2Fjexer%2FTCheckBox.java;h=9cdb303989a1bc53f547277055f8745b6e7f37e1;hb=00691e80f2f135f92be739e2b7e86775a2357276;hp=84c2e41adf7a13d086e704b6490a13a0eccd5359;hpb=3cb993369fa76b6e9fd8ef19db3366349a09a678;p=fanfix.git diff --git a/src/jexer/TCheckBox.java b/src/jexer/TCheckBox.java index 84c2e41..9cdb303 100644 --- a/src/jexer/TCheckBox.java +++ b/src/jexer/TCheckBox.java @@ -28,9 +28,12 @@ */ package jexer; +import static jexer.TKeypress.kbEnter; +import static jexer.TKeypress.kbEsc; import static jexer.TKeypress.kbSpace; import jexer.bits.CellAttributes; import jexer.bits.GraphicsChars; +import jexer.bits.MnemonicString; import jexer.event.TKeypressEvent; import jexer.event.TMouseEvent; @@ -49,9 +52,9 @@ public class TCheckBox extends TWidget { private boolean checked = false; /** - * Label for this checkbox. + * The shortcut and checkbox label. */ - private String label; + private MnemonicString mnemonic; /** * If true, use the window's background color. @@ -77,7 +80,7 @@ public class TCheckBox extends TWidget { // Set parent and window super(parent, x, y, label.length() + 4, 1); - this.label = label; + mnemonic = new MnemonicString(label); this.checked = checked; setCursorVisible(true); @@ -124,11 +127,18 @@ public class TCheckBox extends TWidget { */ @Override public void onKeypress(final TKeypressEvent keypress) { - if (keypress.equals(kbSpace)) { + if (keypress.equals(kbSpace) + || keypress.equals(kbEnter) + ) { checked = !checked; return; } + if (keypress.equals(kbEsc)) { + checked = false; + return; + } + // Pass to parent for the things we don't care about. super.onKeypress(keypress); } @@ -143,11 +153,14 @@ public class TCheckBox extends TWidget { @Override public void draw() { CellAttributes checkboxColor; + CellAttributes mnemonicColor; if (isAbsoluteActive()) { checkboxColor = getTheme().getColor("tcheckbox.active"); + mnemonicColor = getTheme().getColor("tcheckbox.mnemonic.highlighted"); } else { checkboxColor = getTheme().getColor("tcheckbox.inactive"); + mnemonicColor = getTheme().getColor("tcheckbox.mnemonic"); } if (useWindowBackground) { CellAttributes background = getWindow().getBackground(); @@ -161,7 +174,11 @@ public class TCheckBox extends TWidget { putCharXY(1, 0, ' ', checkboxColor); } putCharXY(2, 0, ']', checkboxColor); - putStringXY(4, 0, label, checkboxColor); + putStringXY(4, 0, mnemonic.getRawLabel(), checkboxColor); + if (mnemonic.getShortcutIdx() >= 0) { + putCharXY(4 + mnemonic.getShortcutIdx(), 0, + mnemonic.getShortcut(), mnemonicColor); + } } // ------------------------------------------------------------------------ @@ -186,4 +203,13 @@ public class TCheckBox extends TWidget { this.checked = checked; } + /** + * Get the mnemonic string for this checkbox. + * + * @return mnemonic string + */ + public MnemonicString getMnemonic() { + return mnemonic; + } + }