mirror of
https://github.com/moparisthebest/Yaaic
synced 2025-01-09 20:58:02 -05:00
Scrollback class for scrollback history
This commit is contained in:
parent
1271326483
commit
420d7df0b1
96
src/org/yaaic/model/Scrollback.java
Normal file
96
src/org/yaaic/model/Scrollback.java
Normal file
@ -0,0 +1,96 @@
|
||||
/*
|
||||
Yaaic - Yet Another Android IRC Client
|
||||
|
||||
Copyright 2009-2010 Sebastian Kaspari
|
||||
|
||||
This file is part of Yaaic.
|
||||
|
||||
Yaaic is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Yaaic is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.yaaic.model;
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
||||
/**
|
||||
* Class for handling the scrollback history
|
||||
*
|
||||
* @author Sebastian Kaspari <sebastian@yaaic.org>
|
||||
*/
|
||||
public class Scrollback
|
||||
{
|
||||
public static final int MAX_HISTORY = 10;
|
||||
|
||||
private LinkedList<String> messages;
|
||||
private int pointer;
|
||||
|
||||
/**
|
||||
* Create a new scrollback object
|
||||
*/
|
||||
public Scrollback()
|
||||
{
|
||||
messages = new LinkedList<String>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a message to the history
|
||||
*/
|
||||
public void addMessage(String message)
|
||||
{
|
||||
messages.addLast(message);
|
||||
|
||||
if (messages.size() > MAX_HISTORY) {
|
||||
messages.removeFirst();
|
||||
}
|
||||
|
||||
pointer = messages.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Go back in history
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String goBack()
|
||||
{
|
||||
if (pointer > 0) {
|
||||
pointer--;
|
||||
}
|
||||
|
||||
if (messages.size() >= 0) {
|
||||
return messages.get(pointer);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Go forward in history
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String goForward()
|
||||
{
|
||||
if (pointer < messages.size() - 1) {
|
||||
pointer++;
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
|
||||
if (messages.size() > 0) {
|
||||
return messages.get(pointer);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user