import jexer.bits.CellAttributes;
import jexer.bits.GraphicsChars;
import jexer.bits.MnemonicString;
+import jexer.bits.StringUtils;
import jexer.event.TKeypressEvent;
import jexer.event.TMouseEvent;
final String label, final boolean checked) {
// Set parent and window
- super(parent, x, y, label.length() + 4, 1);
+ super(parent, x, y, StringUtils.width(label) + 4, 1);
mnemonic = new MnemonicString(label);
this.checked = checked;
import jexer.bits.CellAttributes;
import jexer.bits.MnemonicString;
+import jexer.bits.StringUtils;
/**
* TLabel implements a simple label, with an optional mnemonic hotkey action
final TAction action) {
// Set parent and window
- super(parent, false, x, y, text.length(), 1);
+ super(parent, false, x, y, StringUtils.width(text), 1);
mnemonic = new MnemonicString(text);
this.colorKey = colorKey;
import java.util.List;
import jexer.bits.CellAttributes;
+import jexer.bits.StringUtils;
import jexer.event.TKeypressEvent;
import jexer.event.TMouseEvent;
import static jexer.TKeypress.*;
for (int i = 0; i < strings.size(); i++) {
String line = strings.get(i);
- if (line.length() > maxLineWidth) {
- maxLineWidth = line.length();
+ int lineLength = StringUtils.width(line);
+ if (lineLength > maxLineWidth) {
+ maxLineWidth = lineLength;
}
}
import jexer.bits.CellAttributes;
import jexer.bits.GraphicsChars;
import jexer.bits.MnemonicString;
+import jexer.bits.StringUtils;
import jexer.event.TKeypressEvent;
import jexer.event.TMouseEvent;
import static jexer.TKeypress.*;
final String label, final int id) {
// Set parent and window
- super(parent, x, y, label.length() + 4, 1);
+ super(parent, x, y, StringUtils.width(label) + 4, 1);
mnemonic = new MnemonicString(label);
this.id = id;
}
putCharXY(2, 0, ')', radioButtonColor);
putStringXY(4, 0, mnemonic.getRawLabel(), radioButtonColor);
- if (mnemonic.getShortcutIdx() >= 0) {
- putCharXY(4 + mnemonic.getShortcutIdx(), 0,
+ if (mnemonic.getScreenShortcutIdx() >= 0) {
+ putCharXY(4 + mnemonic.getScreenShortcutIdx(), 0,
mnemonic.getShortcut(), mnemonicColor);
}
}
package jexer;
import jexer.bits.CellAttributes;
+import jexer.bits.StringUtils;
/**
* TRadioGroup is a collection of TRadioButtons with a box and label.
final String label) {
// Set parent and window
- super(parent, x, y, label.length() + 4, 2);
+ super(parent, x, y, StringUtils.width(label) + 4, 2);
this.label = label;
}
drawBox(0, 0, getWidth(), getHeight(), radioGroupColor, radioGroupColor,
3, false);
- hLineXY(1, 0, label.length() + 2, ' ', radioGroupColor);
+ hLineXY(1, 0, StringUtils.width(label) + 2, ' ', radioGroupColor);
putStringXY(2, 0, label, radioGroupColor);
}
public TRadioButton addRadioButton(final String label) {
int buttonX = 1;
int buttonY = getChildren().size() + 1;
- if (label.length() + 4 > getWidth()) {
- setWidth(label.length() + 7);
+ if (StringUtils.width(label) + 4 > getWidth()) {
+ setWidth(StringUtils.width(label) + 7);
}
setHeight(getChildren().size() + 3);
TRadioButton button = new TRadioButton(this, buttonX, buttonY, label,
import jexer.bits.CellAttributes;
import jexer.bits.GraphicsChars;
+import jexer.bits.StringUtils;
import jexer.event.TCommandEvent;
import jexer.event.TKeypressEvent;
import jexer.event.TMouseEvent;
* @return the number of columns this takes when drawn
*/
public int width() {
- return this.label.length() + this.key.toString().length() + 3;
+ return StringUtils.width(this.label) +
+ StringUtils.width(this.key.toString()) + 3;
}
/**
// TStatusBar is a parentless widget, because TApplication handles
// its drawing and event routing directly.
- super(null, false, 0, 0, text.length(), 1);
+ super(null, false, 0, 0, StringUtils.width(text), 1);
this.text = text;
setWindow(window);
if (key.selected) {
putCharXY(col++, row, ' ', selectedColor);
putStringXY(col, row, keyStr, selectedColor);
- col += keyStr.length();
+ col += StringUtils.width(keyStr);
putCharXY(col++, row, ' ', selectedColor);
putStringXY(col, row, key.label, selectedColor);
- col += key.label.length();
+ col += StringUtils.width(key.label);
putCharXY(col++, row, ' ', selectedColor);
} else {
putCharXY(col++, row, ' ', barColor);
putStringXY(col, row, keyStr, keyColor);
- col += keyStr.length() + 1;
+ col += StringUtils.width(keyStr) + 1;
putStringXY(col, row, key.label, barColor);
- col += key.label.length();
+ col += StringUtils.width(key.label);
putCharXY(col++, row, ' ', barColor);
}
}
// ------------------------------------------------------------------------
/**
- * Constructor sets up state for getEvent().
+ * Constructor sets up state for getEvent(). If either windowWidth or
+ * windowHeight are less than 1, the terminal is not resized.
*
* @param listener the object this backend needs to wake up when new
* input comes in
// Send dtterm/xterm sequences, which will probably not work because
// allowWindowOps is defaulted to false.
- String resizeString = String.format("\033[8;%d;%dt", windowHeight,
- windowWidth);
- this.output.write(resizeString);
- this.output.flush();
+ if ((windowWidth > 0) && (windowHeight > 0)) {
+ String resizeString = String.format("\033[8;%d;%dt", windowHeight,
+ windowWidth);
+ this.output.write(resizeString);
+ this.output.flush();
+ }
}
/**
int xPixel = cursorX * textWidth + left;
int yPixel = cursorY * textHeight + top;
Cell lCell = logical[cursorX][cursorY];
+ int cursorWidth = textWidth;
+ switch (lCell.getWidth()) {
+ case SINGLE:
+ // NOP
+ break;
+ case LEFT:
+ cursorWidth *= 2;
+ break;
+ case RIGHT:
+ cursorWidth *= 2;
+ xPixel -= textWidth;
+ break;
+ }
gr.setColor(attrToForegroundColor(lCell));
switch (cursorStyle) {
default:
// Fall through...
case UNDERLINE:
- gr.fillRect(xPixel, yPixel + textHeight - 2, textWidth, 2);
+ gr.fillRect(xPixel, yPixel + textHeight - 2, cursorWidth, 2);
break;
case BLOCK:
- gr.fillRect(xPixel, yPixel, textWidth, textHeight);
+ gr.fillRect(xPixel, yPixel, cursorWidth, textHeight);
break;
case OUTLINE:
- gr.drawRect(xPixel, yPixel, textWidth - 1, textHeight - 1);
+ gr.drawRect(xPixel, yPixel, cursorWidth - 1, textHeight - 1);
break;
}
}
*/
private int shortcutIdx = -1;
+ /**
+ * Screen location of the highlighted character (number of text cells
+ * required to display from the beginning to shortcutIdx).
+ */
+ private int screenShortcutIdx = -1;
+
/**
* The raw (uncolored) string.
*/
boolean foundAmp = false;
boolean foundShortcut = false;
int scanShortcutIdx = 0;
+ int scanScreenShortcutIdx = 0;
for (int i = 0; i < label.length(); i++) {
char c = label.charAt(i);
if (c == '&') {
if (foundAmp) {
newLabel += '&';
scanShortcutIdx++;
+ scanScreenShortcutIdx++;
} else {
foundAmp = true;
}
foundAmp = false;
foundShortcut = true;
shortcutIdx = scanShortcutIdx;
+ screenShortcutIdx = scanScreenShortcutIdx;
}
} else {
scanShortcutIdx++;
+ scanScreenShortcutIdx += StringUtils.width(c);
}
}
}
return shortcutIdx;
}
+ /**
+ * Get the screen location of the highlighted character.
+ *
+ * @return the number of text cells required to display from the
+ * beginning of the label to shortcutIdx
+ */
+ public int getScreenShortcutIdx() {
+ return screenShortcutIdx;
+ }
+
/**
* Get the raw (uncolored) string.
*
import jexer.bits.CellAttributes;
import jexer.bits.GraphicsChars;
import jexer.bits.MnemonicString;
+import jexer.bits.StringUtils;
import jexer.event.TKeypressEvent;
import jexer.event.TMouseEvent;
import static jexer.TKeypress.*;
assert (mnemonic.getShortcutIdx() >= 0);
// Recompute width and height to reflect an empty menu
- setWidth(getTitle().length() + 4);
+ setWidth(StringUtils.width(getTitle()) + 4);
setHeight(2);
setActive(false);
import jexer.bits.CellAttributes;
import jexer.bits.GraphicsChars;
import jexer.bits.MnemonicString;
+import jexer.bits.StringUtils;
import jexer.event.TKeypressEvent;
import jexer.event.TMouseEvent;
import jexer.event.TMenuEvent;
setY(y);
setHeight(1);
this.label = mnemonic.getRawLabel();
- setWidth(label.length() + 4);
+ setWidth(StringUtils.width(label) + 4);
this.id = id;
// Default state for some known menu items
putStringXY(2, 0, mnemonic.getRawLabel(), menuColor);
if (key != null) {
String keyLabel = key.toString();
- putStringXY((getWidth() - keyLabel.length() - 2), 0, keyLabel,
- menuColor);
+ putStringXY((getWidth() - StringUtils.width(keyLabel) - 2), 0,
+ keyLabel, menuColor);
}
if (mnemonic.getShortcutIdx() >= 0) {
putCharXY(2 + mnemonic.getShortcutIdx(), 0, mnemonic.getShortcut(),
this.key = key;
if (key != null) {
- int newWidth = (label.length() + 4 + key.toString().length() + 2);
+ int newWidth = (StringUtils.width(label) + 4 +
+ StringUtils.width(key.toString()) + 2);
if (newWidth > getWidth()) {
setWidth(newWidth);
}
import jexer.TWidget;
import jexer.bits.CellAttributes;
import jexer.bits.GraphicsChars;
+import jexer.bits.StringUtils;
import jexer.event.TKeypressEvent;
import jexer.event.TMouseEvent;
import static jexer.TKeypress.*;
}
putStringXY(offset, 0, line, color);
if (selected) {
- putStringXY(offset + line.length(), 0, text, selectedColor);
+ putStringXY(offset + StringUtils.width(line), 0, text, selectedColor);
} else {
- putStringXY(offset + line.length(), 0, text, textColor);
+ putStringXY(offset + StringUtils.width(line), 0, text, textColor);
}
if ((level > 0) && (expandable)) {
if (expanded) {
* @return the maximum number of columns for this item or its children
*/
public int getMaximumColumn() {
- int max = prefix.length() + 4 + text.length();
+ int max = prefix.length() + 4 + StringUtils.width(text);
for (TWidget widget: getChildren()) {
TTreeItem item = (TTreeItem) widget;
- int n = item.prefix.length() + 4 + item.text.length();
+ int n = item.prefix.length() + 4 + StringUtils.width(item.text);
if (n > max) {
max = n;
}