fb00ac47599a5379127f12a41edc915d5b341f3c
[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 label = "";
44
45 /**
46 * Get label text.
47 *
48 * @return label text
49 */
50 public String getLabel() {
51 return label;
52 }
53
54 /**
55 * Set label text.
56 *
57 * @param label new label text
58 */
59 public void setLabel(final String label) {
60 this.label = label;
61 }
62
63 /**
64 * Label color.
65 */
66 private String colorKey;
67
68 /**
69 * Public constructor, using the default "tlabel" for colorKey.
70 *
71 * @param parent parent widget
72 * @param text label on the screen
73 * @param x column relative to parent
74 * @param y row relative to parent
75 */
76 public TLabel(final TWidget parent, final String text, final int x,
77 final int y) {
78
79 this(parent, text, x, y, "tlabel");
80 }
81
82 /**
83 * Public constructor.
84 *
85 * @param parent parent widget
86 * @param text label on the screen
87 * @param x column relative to parent
88 * @param y row relative to parent
89 * @param colorKey ColorTheme key color to use for foreground text
90 */
91 public TLabel(final TWidget parent, final String text, final int x,
92 final int y, final String colorKey) {
93
94 // Set parent and window
95 super(parent, false, x, y, text.length(), 1);
96
97 this.label = text;
98 this.colorKey = colorKey;
99 }
100
101 /**
102 * Draw a static label.
103 */
104 @Override public void draw() {
105 // Setup my color
106 CellAttributes color = new CellAttributes();
107 color.setTo(getTheme().getColor(colorKey));
108 CellAttributes background = getWindow().getBackground();
109 color.setBackColor(background.getBackColor());
110
111 getScreen().putStringXY(0, 0, label, color);
112 }
113
114 }