X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fjexer%2FTLabel.java;h=cc341cfa862964ed9097c425ea4d10b55627ac0c;hb=cfdaf6052ddc5ca44cf19f1f6d9f154cc8443024;hp=c34aee16f32aa699009835b119e95442b8915c7c;hpb=36bad4f912f2b8180ffa25181f0d4900ea1f2a65;p=fanfix.git diff --git a/src/jexer/TLabel.java b/src/jexer/TLabel.java index c34aee1..cc341cf 100644 --- a/src/jexer/TLabel.java +++ b/src/jexer/TLabel.java @@ -30,6 +30,7 @@ package jexer; import jexer.bits.CellAttributes; import jexer.bits.MnemonicString; +import jexer.bits.StringUtils; /** * TLabel implements a simple label, with an optional mnemonic hotkey action @@ -157,9 +158,9 @@ public class TLabel extends TWidget { final TAction action) { // Set parent and window - super(parent, false, x, y, text.length(), 1); + super(parent, false, x, y, 0, 1); - mnemonic = new MnemonicString(text); + setLabel(text); this.colorKey = colorKey; this.useWindowBackground = useWindowBackground; this.action = action; @@ -169,6 +170,27 @@ public class TLabel extends TWidget { // TWidget ---------------------------------------------------------------- // ------------------------------------------------------------------------ + /** + * Override TWidget's width: we can only set width at construction time. + * + * @param width new widget width (ignored) + */ + @Override + public void setWidth(final int width) { + // Do nothing + } + + /** + * Override TWidget's height: we can only set height at construction + * time. + * + * @param height new widget height (ignored) + */ + @Override + public void setHeight(final int height) { + // Do nothing + } + /** * Draw a static label. */ @@ -185,8 +207,8 @@ public class TLabel extends TWidget { mnemonicColor.setBackColor(background.getBackColor()); } putStringXY(0, 0, mnemonic.getRawLabel(), color); - if (mnemonic.getShortcutIdx() >= 0) { - putCharXY(mnemonic.getShortcutIdx(), 0, + if (mnemonic.getScreenShortcutIdx() >= 0) { + putCharXY(mnemonic.getScreenShortcutIdx(), 0, mnemonic.getShortcut(), mnemonicColor); } } @@ -220,6 +242,7 @@ public class TLabel extends TWidget { */ public void setLabel(final String label) { mnemonic = new MnemonicString(label); + super.setWidth(StringUtils.width(mnemonic.getRawLabel())); } /** @@ -245,7 +268,7 @@ public class TLabel extends TWidget { */ public void dispatch() { if (action != null) { - action.DO(); + action.DO(this); } }