import jexer.bits.Cell;
import jexer.bits.CellAttributes;
import jexer.bits.ColorTheme;
+import jexer.bits.StringUtils;
import jexer.event.TCommandEvent;
import jexer.event.TInputEvent;
import jexer.event.TKeypressEvent;
}
} // while (!application.quit)
- assert (dirty == true);
-
- // Flush the screen contents
+ // Flush the screen contents
if (debugThreads) {
System.err.printf("%d %s backend.flushScreen()\n",
System.currentTimeMillis(), Thread.currentThread());
menuMnemonicColor = theme.getColor("tmenu.mnemonic");
}
// Draw the menu title
- getScreen().hLineXY(x, 0, menu.getTitle().length() + 2, ' ',
+ getScreen().hLineXY(x, 0, StringUtils.width(menu.getTitle()) + 2, ' ',
menuColor);
getScreen().putStringXY(x + 1, 0, menu.getTitle(), menuColor);
// Draw the highlight character
// Reset the screen clipping so we can draw the next title.
getScreen().resetClipping();
}
- x += menu.getTitle().length() + 2;
+ x += StringUtils.width(menu.getTitle()) + 2;
}
for (TMenu menu: subMenus) {
for (TMenu menu: menus) {
if ((mouse.getAbsoluteX() >= menu.getTitleX())
&& (mouse.getAbsoluteX() < menu.getTitleX()
- + menu.getTitle().length() + 2)
+ + StringUtils.width(menu.getTitle()) + 2)
) {
menu.setActive(true);
activeMenu = menu;
for (TMenu menu: menus) {
if ((mouse.getAbsoluteX() >= menu.getTitleX())
&& (mouse.getAbsoluteX() < menu.getTitleX()
- + menu.getTitle().length() + 2)
+ + StringUtils.width(menu.getTitle()) + 2)
) {
menu.setActive(true);
activeMenu = menu;
for (TMenu menu: menus) {
menu.setX(x);
menu.setTitleX(x);
- x += menu.getTitle().length() + 2;
+ x += StringUtils.width(menu.getTitle()) + 2;
// Don't let the menu window exceed the screen width
int rightEdge = menu.getX() + menu.getWidth();
import jexer.bits.CellAttributes;
import jexer.bits.GraphicsChars;
+import jexer.bits.StringUtils;
import jexer.event.TKeypressEvent;
import jexer.event.TMouseEvent;
import static jexer.TKeypress.*;
// Draw the title
String title = String.format("%tB %tY", displayCalendar,
displayCalendar);
- int titleLeft = (getWidth() - title.length() - 2) / 2;
+ // This particular title is always single-width (see format string
+ // above), but for completeness let's treat it the same as every
+ // other window title string.
+ int titleLeft = (getWidth() - StringUtils.width(title) - 2) / 2;
putCharXY(titleLeft, 0, ' ', titleColor);
putStringXY(titleLeft + 1, 0, title, titleColor);
- putCharXY(titleLeft + title.length() + 1, 0, ' ',
+ putCharXY(titleLeft + StringUtils.width(title) + 1, 0, ' ',
titleColor);
// Arrows
import java.util.List;
import java.util.Map;
+import jexer.bits.StringUtils;
+
/**
* TDirectoryList shows the files within a directory.
*/
*/
private String renderFile(final File file) {
String name = file.getName();
- if (name.length() > 20) {
+ if (StringUtils.width(name) > 20) {
name = name.substring(0, 17) + "...";
}
return String.format("%-20s %5dk", name, (file.length() / 1024));
import java.util.List;
import java.util.ResourceBundle;
+import jexer.bits.StringUtils;
import jexer.event.TKeypressEvent;
import static jexer.TKeypress.*;
// Determine width and height
String [] lines = caption.split("\n");
- int width = title.length() + 12;
+ int width = StringUtils.width(title) + 12;
setHeight(6 + lines.length);
for (String line: lines) {
- if (line.length() + 4 > width) {
- width = line.length() + 4;
+ if (StringUtils.width(line) + 4 > width) {
+ width = StringUtils.width(line) + 4;
}
}
setWidth(width);
import java.util.List;
import jexer.bits.CellAttributes;
+import jexer.bits.StringUtils;
import jexer.event.TKeypressEvent;
import jexer.event.TMouseEvent;
import static jexer.TKeypress.kbDown;
int topY = 0;
for (int i = begin; i < lines.size(); i++) {
String line = lines.get(i);
- if (hScroller.getValue() < line.length()) {
+ if (hScroller.getValue() < StringUtils.width(line)) {
line = line.substring(hScroller.getValue());
} else {
line = "";
* @param line new line to add
*/
public void addLine(final String line) {
- if (text.length() == 0) {
+ if (StringUtils.width(text) == 0) {
text = line;
} else {
text += "\n\n";
private void computeBounds() {
maxLineWidth = 0;
for (String line : lines) {
- if (line.length() > maxLineWidth) {
- maxLineWidth = line.length();
+ if (StringUtils.width(line) > maxLineWidth) {
+ maxLineWidth = StringUtils.width(line);
}
}
// We have just transitioned from a word to
// whitespace. See if we have enough space to add
// the word to the line.
- if (word.length() + line.length() > n) {
+ if (width(word.toString()) + width(line.toString()) > n) {
// This word will exceed the line length. Wrap
// at it instead.
result.add(line.toString());
line = new StringBuilder();
}
if ((word.toString().startsWith(" "))
- && (line.length() == 0)
+ && (width(line.toString()) == 0)
) {
line.append(word.substring(1));
} else {
}
} // for (int j = 0; j < rawLines[i].length(); j++)
- if (word.length() + line.length() > n) {
+ if (width(word.toString()) + width(line.toString()) > n) {
// This word will exceed the line length. Wrap at it
// instead.
result.add(line.toString());
line = new StringBuilder();
}
if ((word.toString().startsWith(" "))
- && (line.length() == 0)
+ && (width(line.toString()) == 0)
) {
line.append(word.substring(1));
} else {
List<String> lines = left(str, n);
for (String line: lines) {
StringBuilder sb = new StringBuilder();
- for (int i = 0; i < n - line.length(); i++) {
+ for (int i = 0; i < n - width(line); i++) {
sb.append(' ');
}
sb.append(line);
List<String> lines = left(str, n);
for (String line: lines) {
StringBuilder sb = new StringBuilder();
- int l = (n - line.length()) / 2;
- int r = n - line.length() - l;
+ int l = (n - width(line)) / 2;
+ int r = n - width(line) - l;
for (int i = 0; i < l; i++) {
sb.append(' ');
}
import jexer.TScrollableWidget;
import jexer.TVScroller;
import jexer.TWidget;
+import jexer.bits.StringUtils;
import jexer.event.TKeypressEvent;
import jexer.event.TMouseEvent;
import static jexer.TKeypress.*;
selectedRow++;
}
- int lineWidth = item.getText().length()
+ int lineWidth = StringUtils.width(item.getText())
+ item.getPrefix().length() + 4;
if (lineWidth > maxLineWidth) {
maxLineWidth = lineWidth;
import jexer.TScrollableWindow;
import jexer.TVScroller;
import jexer.TWidget;
+import jexer.bits.StringUtils;
import jexer.event.TKeypressEvent;
import jexer.event.TMouseEvent;
import jexer.event.TResizeEvent;
selectedRow++;
}
- int lineWidth = item.getText().length()
+ int lineWidth = StringUtils.width(item.getText())
+ item.getPrefix().length() + 4;
if (lineWidth > maxLineWidth) {
maxLineWidth = lineWidth;