Commit | Line | Data |
---|---|---|
624ce48e KL |
1 | /** |
2 | * Jexer - Java Text User Interface | |
3 | * | |
4 | * Version: $Id$ | |
5 | * | |
6 | * Author: Kevin Lamonte, <a href="mailto:kevin.lamonte@gmail.com">kevin.lamonte@gmail.com</a> | |
7 | * | |
8 | * License: LGPLv3 or later | |
9 | * | |
10 | * Copyright: This module is licensed under the GNU Lesser General | |
11 | * Public License Version 3. Please see the file "COPYING" in this | |
12 | * directory for more information about the GNU Lesser General Public | |
13 | * License Version 3. | |
14 | * | |
15 | * Copyright (C) 2015 Kevin Lamonte | |
16 | * | |
17 | * This program is free software; you can redistribute it and/or | |
18 | * modify it under the terms of the GNU Lesser General Public License | |
19 | * as published by the Free Software Foundation; either version 3 of | |
20 | * the License, or (at your option) any later version. | |
21 | * | |
22 | * This program is distributed in the hope that it will be useful, but | |
23 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
25 | * General Public License for more details. | |
26 | * | |
27 | * You should have received a copy of the GNU Lesser General Public | |
28 | * License along with this program; if not, see | |
29 | * http://www.gnu.org/licenses/, or write to the Free Software | |
30 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | |
31 | * 02110-1301 USA | |
32 | */ | |
33 | package jexer.bits; | |
34 | ||
35 | /** | |
36 | * A single text cell on the screen | |
37 | */ | |
38 | public class Cell extends CellAttributes { | |
39 | ||
40 | /** | |
41 | * The character at this cell | |
42 | */ | |
43 | public char ch; | |
44 | ||
45 | /** | |
46 | * Reset this cell to a blank | |
47 | */ | |
48 | @Override | |
49 | public void reset() { | |
50 | super.reset(); | |
51 | ch = ' '; | |
52 | } | |
53 | ||
54 | /** | |
55 | * Returns true if this cell has default attributes | |
56 | */ | |
57 | public boolean isBlank() { | |
58 | if ((foreColor.equals(Color.WHITE)) && | |
59 | (backColor.equals(Color.BLACK)) && | |
60 | (bold == false) && | |
61 | (blink == false) && | |
62 | (reverse == false) && | |
63 | (underline == false) && | |
64 | (protect == false) && | |
65 | (ch == ' ')) { | |
66 | return true; | |
67 | } | |
68 | ||
69 | return false; | |
70 | } | |
71 | ||
72 | /** | |
73 | * Comparison. All fields must match to return true. | |
74 | */ | |
75 | @Override | |
76 | public boolean equals(Object rhs) { | |
77 | if (!(rhs instanceof Cell)) { | |
78 | return false; | |
79 | } | |
80 | ||
81 | Cell that = (Cell)rhs; | |
82 | return (super.equals(rhs) && | |
83 | (ch == that.ch)); | |
84 | } | |
85 | ||
86 | /** | |
87 | * Set my field values to that's field | |
88 | */ | |
89 | @Override | |
90 | public void setTo(Object rhs) { | |
91 | CellAttributes thatAttr = (CellAttributes)rhs; | |
92 | super.setTo(thatAttr); | |
93 | ||
94 | if (rhs instanceof Cell) { | |
95 | Cell that = (Cell)rhs; | |
96 | this.ch = that.ch; | |
97 | } | |
98 | } | |
99 | ||
100 | /** | |
101 | * Set my field attr values to that's field | |
102 | */ | |
103 | public void setAttr(CellAttributes that) { | |
104 | super.setTo(that); | |
105 | } | |
106 | ||
107 | /** | |
108 | * Public constructor | |
109 | */ | |
110 | public Cell() { | |
111 | reset(); | |
112 | } | |
113 | ||
114 | /** | |
115 | * Public constructor | |
116 | * | |
117 | * @param ch character to set to | |
118 | */ | |
119 | public Cell(char ch) { | |
120 | reset(); | |
121 | this.ch = ch; | |
122 | } | |
123 | ||
124 | /** | |
125 | * Make human-readable description of this Cell | |
126 | */ | |
127 | @Override | |
128 | public String toString() { | |
129 | return String.format("fore: %d back: %d bold: %s blink: %s ch %c", | |
130 | foreColor, backColor, bold, blink, ch); | |
131 | } | |
132 | } | |
133 |