| 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 | * Get label text. |
| 47 | * |
| 48 | * @return label text |
| 49 | */ |
| 50 | public String getText() { |
| 51 | return text; |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Set label text. |
| 56 | * |
| 57 | * @param text new label text |
| 58 | */ |
| 59 | public void setText(final String text) { |
| 60 | this.text = text; |
| 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); |
| 96 | |
| 97 | this.text = text; |
| 98 | setX(x); |
| 99 | setY(y); |
| 100 | setHeight(1); |
| 101 | setWidth(text.length()); |
| 102 | this.colorKey = colorKey; |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * Draw a static label. |
| 107 | */ |
| 108 | @Override public void draw() { |
| 109 | // Setup my color |
| 110 | CellAttributes color = new CellAttributes(); |
| 111 | color.setTo(getTheme().getColor(colorKey)); |
| 112 | CellAttributes background = getWindow().getBackground(); |
| 113 | color.setBackColor(background.getBackColor()); |
| 114 | |
| 115 | getScreen().putStrXY(0, 0, text, color); |
| 116 | } |
| 117 | |
| 118 | } |