TButton and TLabel
[fanfix.git] / src / jexer / TLabel.java
1 /**
2 * Jexer - Java Text User Interface
3 *
4 * License: LGPLv3 or later
5 *
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.
9 *
10 * Copyright (C) 2015 Kevin Lamonte
11 *
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.
16 *
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.
21 *
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
26 * 02110-1301 USA
27 *
28 * @author Kevin Lamonte [kevin.lamonte@gmail.com]
29 * @version 1
30 */
31 package jexer;
32
33 import jexer.bits.CellAttributes;
34
35 /**
36 * TLabel implements a simple label.
37 */
38 public final class TLabel extends TWidget {
39
40 /**
41 * Label text.
42 */
43 private String text = "";
44
45 /**
46 * Label color.
47 */
48 private String colorKey;
49
50 /**
51 * Public constructor, using the default "tlabel" for colorKey.
52 *
53 * @param parent parent widget
54 * @param text label on the screen
55 * @param x column relative to parent
56 * @param y row relative to parent
57 */
58 public TLabel(final TWidget parent, final String text, final int x,
59 final int y) {
60
61 this(parent, text, x, y, "tlabel");
62 }
63
64 /**
65 * Public constructor.
66 *
67 * @param parent parent widget
68 * @param text label on the screen
69 * @param x column relative to parent
70 * @param y row relative to parent
71 * @param colorKey ColorTheme key color to use for foreground text
72 */
73 public TLabel(final TWidget parent, final String text, final int x,
74 final int y, final String colorKey) {
75
76 // Set parent and window
77 super(parent, false);
78
79 this.text = text;
80 setX(x);
81 setY(y);
82 setHeight(1);
83 setWidth(text.length());
84 this.colorKey = colorKey;
85 }
86
87 /**
88 * Draw a static label.
89 */
90 @Override public void draw() {
91 // Setup my color
92 CellAttributes color = new CellAttributes();
93 color.setTo(getTheme().getColor(colorKey));
94 CellAttributes background = getWindow().getBackground();
95 color.setBackColor(background.getBackColor());
96
97 getScreen().putStrXY(0, 0, text, color);
98 }
99
100 }