added option to limit the number of messages in list
This commit is contained in:
parent
2bc52699c6
commit
9d7275db7e
@ -26,14 +26,14 @@
|
|||||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
* $Id: MessageList.java,v 1.13 2009/06/25 15:46:57 fros4943 Exp $
|
* $Id: MessageList.java,v 1.14 2009/10/19 17:33:25 fros4943 Exp $
|
||||||
*
|
*
|
||||||
* -----------------------------------------------------------------
|
* -----------------------------------------------------------------
|
||||||
*
|
*
|
||||||
* Author : Adam Dunkels, Joakim Eriksson, Niclas Finne, Fredrik Osterlind
|
* Author : Adam Dunkels, Joakim Eriksson, Niclas Finne, Fredrik Osterlind
|
||||||
* Created : 2006-06-14
|
* Created : 2006-06-14
|
||||||
* Updated : $Date: 2009/06/25 15:46:57 $
|
* Updated : $Date: 2009/10/19 17:33:25 $
|
||||||
* $Revision: 1.13 $
|
* $Revision: 1.14 $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package se.sics.cooja.dialogs;
|
package se.sics.cooja.dialogs;
|
||||||
@ -80,12 +80,22 @@ public class MessageList extends JList {
|
|||||||
private JPopupMenu popup = null;
|
private JPopupMenu popup = null;
|
||||||
private boolean hideNormal = false;
|
private boolean hideNormal = false;
|
||||||
|
|
||||||
|
private int max = -1;
|
||||||
|
|
||||||
public MessageList() {
|
public MessageList() {
|
||||||
super.setModel(new MessageModel());
|
super.setModel(new MessageModel());
|
||||||
setCellRenderer(new MessageRenderer());
|
setCellRenderer(new MessageRenderer());
|
||||||
setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param max Maximum number of messages
|
||||||
|
*/
|
||||||
|
public MessageList(int max) {
|
||||||
|
this();
|
||||||
|
this.max = max;
|
||||||
|
}
|
||||||
|
|
||||||
public Color getForeground(int type) {
|
public Color getForeground(int type) {
|
||||||
Color c = type > 0 && type <= foregrounds.length
|
Color c = type > 0 && type <= foregrounds.length
|
||||||
? foregrounds[type - 1] : null;
|
? foregrounds[type - 1] : null;
|
||||||
@ -158,6 +168,10 @@ public class MessageList extends JList {
|
|||||||
while (messages.size() > getModel().getSize()) {
|
while (messages.size() > getModel().getSize()) {
|
||||||
((DefaultListModel) getModel()).addElement(messages.get(getModel().getSize()));
|
((DefaultListModel) getModel()).addElement(messages.get(getModel().getSize()));
|
||||||
}
|
}
|
||||||
|
while (max > 0 && getModel().getSize() > max) {
|
||||||
|
((DefaultListModel) getModel()).removeElementAt(0);
|
||||||
|
messages.remove(0);
|
||||||
|
}
|
||||||
|
|
||||||
if (scroll) {
|
if (scroll) {
|
||||||
ensureIndexIsVisible(getModel().getSize() - 1);
|
ensureIndexIsVisible(getModel().getSize() - 1);
|
||||||
|
Loading…
Reference in New Issue
Block a user