2 * This file is part of lanterna (http://code.google.com/p/lanterna/).
4 * lanterna is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 * Copyright (C) 2010-2015 Martin
19 package com
.googlecode
.lanterna
.terminal
;
21 import com
.googlecode
.lanterna
.TerminalSize
;
22 import com
.googlecode
.lanterna
.graphics
.TextGraphics
;
24 import java
.io
.IOException
;
25 import java
.util
.ArrayList
;
26 import java
.util
.List
;
29 * Containing a some very fundamental functionality that should be common (and usable) to all terminal implementations.
30 * All the Terminal implementers within Lanterna extends from this class.
34 public abstract class AbstractTerminal
implements Terminal
{
36 private final List
<ResizeListener
> resizeListeners
;
37 private TerminalSize lastKnownSize
;
39 protected AbstractTerminal() {
40 this.resizeListeners
= new ArrayList
<ResizeListener
>();
41 this.lastKnownSize
= null;
45 public void addResizeListener(ResizeListener listener
) {
46 if (listener
!= null) {
47 resizeListeners
.add(listener
);
52 public void removeResizeListener(ResizeListener listener
) {
53 if (listener
!= null) {
54 resizeListeners
.remove(listener
);
59 * Call this method when the terminal has been resized or the initial size of the terminal has been discovered. It
60 * will trigger all resize listeners, but only if the size has changed from before.
62 * @param columns Number of columns in the new size
63 * @param rows Number of rows in the new size
65 protected synchronized void onResized(int columns
, int rows
) {
66 TerminalSize newSize
= new TerminalSize(columns
, rows
);
67 if (lastKnownSize
== null || !lastKnownSize
.equals(newSize
)) {
68 lastKnownSize
= newSize
;
69 for (ResizeListener resizeListener
: resizeListeners
) {
70 resizeListener
.onResized(this, lastKnownSize
);
76 public TextGraphics
newTextGraphics() throws IOException
{
77 return new TerminalTextGraphics(this);