Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/altara/mars/swingui/ChangeListModel.java


1   /* MARS Network Monitor Swing User Interface
2      Copyright (C) 1999 Brian H. Trammell
3      Copyright (C) 2002 Leapfrog Research & Development, LLC
4   
5     This program is free software; you can redistribute it and/or
6     modify it under the terms of the GNU General Public License
7     as published by the Free Software Foundation; either version 2
8     of the License, or (at your option) any later version.
9   
10    This program is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13    GNU General Public License for more details.
14    
15    You should have received a copy of the GNU General Public License
16    along with this program; if not, it is available at 
17    http:///www.gnu.org/copyleft/gpl.html, or by writing to the
18    Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19    Boston, MA  02111-1307, USA.
20  */
21  
22  package org.altara.mars.swingui;
23  
24  import org.altara.mars.*;
25  import org.altara.mars.engine.*;
26  import java.util.*;
27  import java.awt.*;
28  import java.awt.event.*;
29  import javax.swing.*;
30  import javax.swing.tree.*;
31  import javax.swing.event.*;
32  
33  /** ChangeListModel contains a list of service status change events.
34    It provides the user with a way to view the history of service
35    status changes. 
36  */
37  
38  public class ChangeListModel extends AbstractListModel
39      implements StatusChangeListener {
40  
41    private static final int DEFAULT_MAXLEN = 200;
42  
43    private ArrayList changeList;
44    private int maxlen;
45  
46    public ChangeListModel() {
47      this.changeList = new ArrayList();
48      this.maxlen = DEFAULT_MAXLEN;
49    }
50    
51    public int getSize() {
52      return changeList.size();
53    }
54  
55    public Object getElementAt(int index) {
56      return changeList.get(index);
57    }
58  
59    public void statusChanged(StatusChangeEvent sce) {
60      // insert the change event at the head of the list
61      changeList.add(0,sce);
62      // fire notification
63      fireIntervalAdded(this,0,0);
64      // remove the last element if the list is now too large
65      if (changeList.size() > maxlen) {
66        changeList.remove(changeList.size()-1);
67        fireIntervalRemoved(this,changeList.size(),changeList.size());
68      }
69    }
70  
71    void clear() {
72      int oldsz = changeList.size();
73      changeList.clear();
74      if (oldsz > 0) fireIntervalRemoved(this,0,oldsz-1);
75    }
76  }