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
;
24 * This class is a simple implementation of Terminal.ResizeListener which will keep track of the size of the terminal
25 * and let you know if the terminal has been resized since you last checked. This can be useful to avoid threading
26 * problems with the resize callback when your application is using a main event loop.
30 @SuppressWarnings("WeakerAccess")
31 public class SimpleTerminalResizeListener
implements ResizeListener
{
34 TerminalSize lastKnownSize
;
37 * Creates a new SimpleTerminalResizeListener
38 * @param initialSize Before any resize event, this listener doesn't know the size of the terminal. By supplying a
39 * value here, you control what getLastKnownSize() will return if invoked before any resize events has reached us.
41 public SimpleTerminalResizeListener(TerminalSize initialSize
) {
42 this.wasResized
= false;
43 this.lastKnownSize
= initialSize
;
47 * Checks if the terminal was resized since the last time this method was called. If this is the first time calling
48 * this method, the result is going to be based on if the terminal has been resized since this listener was attached
51 * @return true if the terminal was resized, false otherwise
53 public synchronized boolean isTerminalResized() {
64 * Returns the last known size the Terminal is supposed to have.
66 * @return Size of the terminal, as of the last resize update
68 public TerminalSize
getLastKnownSize() {
73 public synchronized void onResized(Terminal terminal
, TerminalSize newSize
) {
74 this.wasResized
= true;
75 this.lastKnownSize
= newSize
;