Merge branch 'subtree'
[fanfix.git] / src / jexer / TPasswordField.java
index 696f5e21d17fa2c96f9f1046ff6d32741458a688..0be2b98ce3ff73e0a9668b621f2639df791f0c1d 100644 (file)
@@ -3,7 +3,7 @@
  *
  * The MIT License (MIT)
  *
- * Copyright (C) 2017 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"),
 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 class TPasswordField extends TField {
 
+    // ------------------------------------------------------------------------
+    // Constructors -----------------------------------------------------------
+    // ------------------------------------------------------------------------
+
     /**
      * Public constructor.
      *
@@ -87,6 +92,10 @@ public class TPasswordField extends TField {
         super(parent, x, y, width, fixed, text, enterAction, updateAction);
     }
 
+    // ------------------------------------------------------------------------
+    // TField -----------------------------------------------------------------
+    // ------------------------------------------------------------------------
+
     /**
      * Draw the text field.
      */
@@ -103,17 +112,16 @@ public 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().