2 * Jexer - Java Text User Interface
4 * License: LGPLv3 or later
6 * This module is licensed under the GNU Lesser General Public License
7 * Version 3. Please see the file "COPYING" in this directory for more
8 * information about the GNU Lesser General Public License Version 3.
10 * Copyright (C) 2015 Kevin Lamonte
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public License
14 * as published by the Free Software Foundation; either version 3 of
15 * the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this program; if not, see
24 * http://www.gnu.org/licenses/, or write to the Free Software
25 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
28 * @author Kevin Lamonte [kevin.lamonte@gmail.com]
33 import jexer
.bits
.CellAttributes
;
34 import jexer
.bits
.GraphicsChars
;
37 * TField implements an editable text field.
39 public final class TPasswordField
extends TField
{
44 * @param parent parent widget
45 * @param x column relative to parent
46 * @param y row relative to parent
47 * @param width visible text width
48 * @param fixed if true, the text cannot exceed the display width
50 public TPasswordField(final TWidget parent
, final int x
, final int y
,
51 final int width
, final boolean fixed
) {
53 this(parent
, x
, y
, width
, fixed
, "", null, null);
59 * @param parent parent widget
60 * @param x column relative to parent
61 * @param y row relative to parent
62 * @param width visible text width
63 * @param fixed if true, the text cannot exceed the display width
64 * @param text initial text, default is empty string
66 public TPasswordField(final TWidget parent
, final int x
, final int y
,
67 final int width
, final boolean fixed
, final String text
) {
69 this(parent
, x
, y
, width
, fixed
, text
, null, null);
75 * @param parent parent widget
76 * @param x column relative to parent
77 * @param y row relative to parent
78 * @param width visible text width
79 * @param fixed if true, the text cannot exceed the display width
80 * @param text initial text, default is empty string
81 * @param enterAction function to call when enter key is pressed
82 * @param updateAction function to call when the text is updated
84 public TPasswordField(final TWidget parent
, final int x
, final int y
,
85 final int width
, final boolean fixed
, final String text
,
86 final TAction enterAction
, final TAction updateAction
) {
88 // Set parent and window
89 super(parent
, x
, y
, width
, fixed
, text
, enterAction
, updateAction
);
93 * Draw the text field.
97 CellAttributes fieldColor
;
99 boolean showStars
= false;
100 if (isAbsoluteActive()) {
101 fieldColor
= getTheme().getColor("tfield.active");
103 fieldColor
= getTheme().getColor("tfield.inactive");
107 int end
= windowStart
+ getWidth();
108 if (end
> text
.length()) {
112 getScreen().hLineXY(0, 0, getWidth(), GraphicsChars
.HATCH
, fieldColor
);
114 getScreen().hLineXY(0, 0, getWidth() - 2, '*',
117 getScreen().putStringXY(0, 0, text
.substring(windowStart
, end
),
121 // Fix the cursor, it will be rendered by TApplication.drawAll().