X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fjexer%2FTPasswordField.java;h=9c200d7dc7dcfea44a2fef0d3f59f8df9505ec81;hb=12b90437b5f22c2ae6e9b9b14c3b62b60f6143e5;hp=3e92165481f8dcddb7f6b778ca90a3a7c496cebc;hpb=e16dda65585466c8987bd1efd718431450a96605;p=nikiroo-utils.git diff --git a/src/jexer/TPasswordField.java b/src/jexer/TPasswordField.java index 3e92165..9c200d7 100644 --- a/src/jexer/TPasswordField.java +++ b/src/jexer/TPasswordField.java @@ -3,7 +3,7 @@ * * The MIT License (MIT) * - * Copyright (C) 2016 Kevin Lamonte + * Copyright (C) 2019 Kevin Lamonte * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -30,11 +30,17 @@ package jexer; import jexer.bits.CellAttributes; import jexer.bits.GraphicsChars; +import jexer.bits.StringUtils; /** - * TField implements an editable text field. + * TPasswordField implements an editable text field that displays + * stars/asterisks when it is not active. */ -public final class TPasswordField extends TField { +public class TPasswordField extends TField { + + // ------------------------------------------------------------------------ + // Constructors ----------------------------------------------------------- + // ------------------------------------------------------------------------ /** * Public constructor. @@ -87,6 +93,10 @@ public final class TPasswordField extends TField { super(parent, x, y, width, fixed, text, enterAction, updateAction); } + // ------------------------------------------------------------------------ + // TField ----------------------------------------------------------------- + // ------------------------------------------------------------------------ + /** * Draw the text field. */ @@ -103,17 +113,16 @@ public final class TPasswordField extends TField { } int end = windowStart + getWidth(); - if (end > text.length()) { - end = text.length(); + if (end > StringUtils.width(text)) { + end = StringUtils.width(text); } - getScreen().hLineXY(0, 0, getWidth(), GraphicsChars.HATCH, fieldColor); + hLineXY(0, 0, getWidth(), backgroundChar, fieldColor); if (showStars) { - getScreen().hLineXY(0, 0, getWidth() - 2, '*', - fieldColor); + hLineXY(0, 0, getWidth() - 2, '*', fieldColor); } else { - getScreen().putStringXY(0, 0, text.substring(windowStart, end), - fieldColor); + putStringXY(0, 0, text.substring(screenToTextPosition(windowStart), + screenToTextPosition(end)), fieldColor); } // Fix the cursor, it will be rendered by TApplication.drawAll().