Commit | Line | Data |
---|---|---|
daa4106c | 1 | /* |
34a42e78 KL |
2 | * Jexer - Java Text User Interface |
3 | * | |
e16dda65 | 4 | * The MIT License (MIT) |
34a42e78 | 5 | * |
a2018e99 | 6 | * Copyright (C) 2017 Kevin Lamonte |
34a42e78 | 7 | * |
e16dda65 KL |
8 | * Permission is hereby granted, free of charge, to any person obtaining a |
9 | * copy of this software and associated documentation files (the "Software"), | |
10 | * to deal in the Software without restriction, including without limitation | |
11 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, | |
12 | * and/or sell copies of the Software, and to permit persons to whom the | |
13 | * Software is furnished to do so, subject to the following conditions: | |
34a42e78 | 14 | * |
e16dda65 KL |
15 | * The above copyright notice and this permission notice shall be included in |
16 | * all copies or substantial portions of the Software. | |
34a42e78 | 17 | * |
e16dda65 KL |
18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |
21 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |
23 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |
24 | * DEALINGS IN THE SOFTWARE. | |
34a42e78 KL |
25 | * |
26 | * @author Kevin Lamonte [kevin.lamonte@gmail.com] | |
27 | * @version 1 | |
28 | */ | |
29 | package jexer.tterminal; | |
30 | ||
31 | import jexer.bits.Cell; | |
32 | import jexer.bits.CellAttributes; | |
33 | ||
34 | /** | |
35 | * This represents a single line of the display buffer. | |
36 | */ | |
37 | public final class DisplayLine { | |
38 | /** | |
39 | * Maximum line length. | |
40 | */ | |
41 | private static final int MAX_LINE_LENGTH = 256; | |
42 | ||
43 | /** | |
44 | * The characters/attributes of the line. | |
45 | */ | |
46 | private Cell [] chars; | |
47 | ||
48 | /** | |
49 | * Get the Cell at a specific column. | |
50 | * | |
51 | * @param idx the character index | |
52 | * @return the Cell | |
53 | */ | |
54 | public Cell charAt(final int idx) { | |
55 | return chars[idx]; | |
56 | } | |
57 | ||
58 | /** | |
59 | * Get the length of this line. | |
60 | * | |
61 | * @return line length | |
62 | */ | |
63 | public int length() { | |
64 | return chars.length; | |
65 | } | |
66 | ||
67 | /** | |
68 | * Double-width line flag. | |
69 | */ | |
70 | private boolean doubleWidth = false; | |
71 | ||
72 | /** | |
73 | * Get double width flag. | |
74 | * | |
75 | * @return double width | |
76 | */ | |
77 | public boolean isDoubleWidth() { | |
78 | return doubleWidth; | |
79 | } | |
80 | ||
81 | /** | |
82 | * Set double width flag. | |
83 | * | |
84 | * @param doubleWidth new value for double width flag | |
85 | */ | |
86 | public void setDoubleWidth(final boolean doubleWidth) { | |
87 | this.doubleWidth = doubleWidth; | |
88 | } | |
89 | ||
90 | /** | |
91 | * Double height line flag. Valid values are: | |
92 | * | |
93 | * <p><pre> | |
94 | * 0 = single height | |
95 | * 1 = top half double height | |
96 | * 2 = bottom half double height | |
97 | * </pre> | |
98 | */ | |
99 | private int doubleHeight = 0; | |
100 | ||
101 | /** | |
102 | * Get double height flag. | |
103 | * | |
104 | * @return double height | |
105 | */ | |
106 | public int getDoubleHeight() { | |
107 | return doubleHeight; | |
108 | } | |
109 | ||
110 | /** | |
111 | * Set double height flag. | |
112 | * | |
113 | * @param doubleHeight new value for double height flag | |
114 | */ | |
115 | public void setDoubleHeight(final int doubleHeight) { | |
116 | this.doubleHeight = doubleHeight; | |
117 | } | |
118 | ||
119 | /** | |
120 | * DECSCNM - reverse video. We copy the flag to the line so that | |
121 | * reverse-mode scrollback lines still show inverted colors correctly. | |
122 | */ | |
123 | private boolean reverseColor = false; | |
124 | ||
125 | /** | |
126 | * Get reverse video flag. | |
127 | * | |
128 | * @return reverse video | |
129 | */ | |
130 | public boolean isReverseColor() { | |
131 | return reverseColor; | |
132 | } | |
133 | ||
134 | /** | |
135 | * Set double-height flag. | |
136 | * | |
137 | * @param reverseColor new value for reverse video flag | |
138 | */ | |
139 | public void setReverseColor(final boolean reverseColor) { | |
140 | this.reverseColor = reverseColor; | |
141 | } | |
142 | ||
143 | /** | |
144 | * Public constructor sets everything to drawing attributes. | |
145 | * | |
146 | * @param attr current drawing attributes | |
147 | */ | |
148 | public DisplayLine(final CellAttributes attr) { | |
149 | chars = new Cell[MAX_LINE_LENGTH]; | |
150 | for (int i = 0; i < chars.length; i++) { | |
151 | chars[i] = new Cell(); | |
152 | chars[i].setTo(attr); | |
153 | } | |
154 | } | |
155 | ||
156 | /** | |
157 | * Insert a character at the specified position. | |
158 | * | |
159 | * @param idx the character index | |
160 | * @param newCell the new Cell | |
161 | */ | |
162 | public void insert(final int idx, final Cell newCell) { | |
163 | System.arraycopy(chars, idx, chars, idx + 1, chars.length - idx - 1); | |
f5a270d5 KL |
164 | chars[idx] = new Cell(); |
165 | chars[idx].setTo(newCell); | |
34a42e78 KL |
166 | } |
167 | ||
168 | /** | |
169 | * Replace character at the specified position. | |
170 | * | |
171 | * @param idx the character index | |
172 | * @param newCell the new Cell | |
173 | */ | |
174 | public void replace(final int idx, final Cell newCell) { | |
bd8d51fa | 175 | chars[idx].setTo(newCell); |
34a42e78 KL |
176 | } |
177 | ||
178 | /** | |
179 | * Set the Cell at the specified position to the blank (reset). | |
180 | * | |
181 | * @param idx the character index | |
182 | */ | |
183 | public void setBlank(final int idx) { | |
184 | chars[idx].reset(); | |
185 | } | |
186 | ||
187 | /** | |
188 | * Set the character (just the char, not the attributes) at the specified | |
189 | * position to ch. | |
190 | * | |
191 | * @param idx the character index | |
192 | * @param ch the new char | |
193 | */ | |
194 | public void setChar(final int idx, final char ch) { | |
195 | chars[idx].setChar(ch); | |
196 | } | |
197 | ||
198 | /** | |
199 | * Set the attributes (just the attributes, not the char) at the | |
200 | * specified position to attr. | |
201 | * | |
202 | * @param idx the character index | |
203 | * @param attr the new attributes | |
204 | */ | |
205 | public void setAttr(final int idx, final CellAttributes attr) { | |
206 | chars[idx].setAttr(attr); | |
207 | } | |
208 | ||
209 | /** | |
bd8d51fa KL |
210 | * Delete character at the specified position, filling in the new |
211 | * character on the right with newCell. | |
34a42e78 KL |
212 | * |
213 | * @param idx the character index | |
214 | * @param newCell the new Cell | |
215 | */ | |
216 | public void delete(final int idx, final Cell newCell) { | |
217 | System.arraycopy(chars, idx + 1, chars, idx, chars.length - idx - 1); | |
f5a270d5 KL |
218 | chars[chars.length - 1] = new Cell(); |
219 | chars[chars.length - 1].setTo(newCell); | |
34a42e78 KL |
220 | } |
221 | ||
222 | } |